1.3.6-2 Test Build - Individual file uploads & cloudariny fixes.
This commit is contained in:
@@ -5,6 +5,7 @@ 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
|
||||
|
||||
@@ -17,9 +18,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.localUri.split(".").pop();
|
||||
let key = `${bodyshop.id}/${jobId}/${(filename || newFile.data.name).replace(
|
||||
// const newFile = await (await fetch(imageData.localUri)).blob();
|
||||
let extension = imageData.filename.split(".").pop();
|
||||
let key = `${bodyshop.id}/${jobId}/${filename.replace(
|
||||
/\.[^/.]+$/,
|
||||
""
|
||||
)}-${new Date().getTime()}`;
|
||||
@@ -29,8 +30,8 @@ export const handleUpload = async (ev, context) => {
|
||||
mediaId,
|
||||
imageData,
|
||||
extension,
|
||||
newFile.type,
|
||||
newFile,
|
||||
mime.getType(imageData.uri),
|
||||
//newFile,
|
||||
onError,
|
||||
onSuccess,
|
||||
onProgress,
|
||||
@@ -45,7 +46,7 @@ export const uploadToCloudinary = async (
|
||||
imageData,
|
||||
extension,
|
||||
fileType,
|
||||
file,
|
||||
//file,
|
||||
onError,
|
||||
onSuccess,
|
||||
onProgress,
|
||||
@@ -93,7 +94,10 @@ export const uploadToCloudinary = async (
|
||||
|
||||
var signature = signedURLResponse.data;
|
||||
var options = {
|
||||
headers: { "X-Requested-With": "XMLHttpRequest" },
|
||||
headers: {
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
onUploadProgress: (e) => {
|
||||
if (onProgress)
|
||||
onProgress({ percent: e.loaded / e.total, loaded: e.loaded });
|
||||
@@ -104,7 +108,7 @@ export const uploadToCloudinary = async (
|
||||
formData.append("file", {
|
||||
uri: imageData.localUri,
|
||||
type: fileType,
|
||||
name: file.data.name,
|
||||
name: imageData.filename,
|
||||
});
|
||||
formData.append("upload_preset", upload_preset);
|
||||
formData.append("api_key", env.REACT_APP_CLOUDINARY_API_KEY);
|
||||
@@ -178,7 +182,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) }
|
||||
: {}),
|
||||
|
||||
Reference in New Issue
Block a user