1.3.6-5 Resolve uploads for cloudinary.

This commit is contained in:
Patrick Fic
2022-05-19 15:49:59 -07:00
parent 114c2940a2
commit 26e9bf87c8
7 changed files with 512 additions and 522 deletions

View File

@@ -5,7 +5,6 @@ import { INSERT_NEW_DOCUMENT } from "../graphql/documents.queries";
import { axiosAuthInterceptorId } from "./CleanAxios";
import * as MediaLibrary from "expo-media-library";
import { gql } from "@apollo/client";
import mime from "mime";
//Context: currentUserEmail, bodyshop, jobid, invoiceid
@@ -18,9 +17,9 @@ export const handleUpload = async (ev, context) => {
const { bodyshop, jobId } = context;
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
// const newFile = await (await fetch(imageData.localUri)).blob();
let extension = imageData.filename.split(".").pop();
let key = `${bodyshop.id}/${jobId}/${filename.replace(
const newFile = await (await fetch(imageData.localUri)).blob();
let extension = imageData.localUri.split(".").pop();
let key = `${bodyshop.id}/${jobId}/${(filename || newFile.data.name).replace(
/\.[^/.]+$/,
""
)}-${new Date().getTime()}`;
@@ -30,8 +29,8 @@ export const handleUpload = async (ev, context) => {
mediaId,
imageData,
extension,
mime.getType(imageData.uri),
//newFile,
newFile.type,
newFile,
onError,
onSuccess,
onProgress,
@@ -46,7 +45,7 @@ export const uploadToCloudinary = async (
imageData,
extension,
fileType,
//file,
file,
onError,
onSuccess,
onProgress,
@@ -108,7 +107,7 @@ export const uploadToCloudinary = async (
formData.append("file", {
uri: imageData.localUri,
type: fileType,
name: imageData.filename,
name: file.data.name,
});
formData.append("upload_preset", upload_preset);
formData.append("api_key", env.REACT_APP_CLOUDINARY_API_KEY);
@@ -182,7 +181,7 @@ export const uploadToCloudinary = async (
type: fileType,
extension: extension,
bodyshopid: bodyshop.id,
size: cloudinaryUploadResponse.data.bytes, //|| file.size,
size: cloudinaryUploadResponse.data.bytes || file.size,
...(imageData.creationTime
? { takenat: new Date(imageData.creationTime) }
: {}),