1.3.6-2 Test Build - Individual file uploads & cloudariny fixes.

This commit is contained in:
Patrick Fic
2022-05-17 18:58:10 -07:00
parent 9c101e8bd4
commit 5633eeb24d
5 changed files with 69 additions and 68 deletions

View File

@@ -1,8 +1,8 @@
import axios from "axios";
import { store } from "../redux/store";
import mime from "mime";
import * as MediaLibrary from "expo-media-library";
import * as ImageManipulator from "expo-image-manipulator";
import * as MediaLibrary from "expo-media-library";
import mime from "mime";
import { store } from "../redux/store";
axios.interceptors.request.use(
function (config) {
@@ -40,7 +40,8 @@ export const handleLocalUpload = async ({ ev, context }) => {
ims_token: bodyshop.localmediatoken,
},
onUploadProgress: (e) => {
if (onProgress) onProgress({ percent: (e.loaded / e.total) * 100 });
if (onProgress)
onProgress({ percent: (e.loaded / e.total) * 100, loaded: e.loaded });
},
};
@@ -54,39 +55,38 @@ export const handleLocalUpload = async ({ ev, context }) => {
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
const mimeType = mime.getType(imageData.uri);
let thumb;
//let thumb;
let fileData = {
uri: null,
type: null,
name: null,
};
if (mimeType === "image/heic") {
try {
thumb = await ImageManipulator.manipulateAsync(imageData.uri, [], {
format: "jpeg",
base64: true,
compress: 0.75,
});
const name = imageData.filename.split(".");
name.pop();
fileData = {
uri: thumb.uri,
type: "image/jpeg",
name: name.join("") + ".jpeg",
};
} catch (error) {
console.log(error);
onError && onError(error.message);
}
} else {
fileData = {
uri: imageData.localUri || imageData.uri,
type: mimeType,
name: filename,
};
}
// if (mimeType === "image/heic") {
// try {
// thumb = await ImageManipulator.manipulateAsync(imageData.uri, [], {
// format: "jpeg",
// base64: true,
// compress: 0.75,
// });
// const name = imageData.filename.split(".");
// name.pop();
// fileData = {
// uri: thumb.uri,
// type: "image/jpeg",
// name: name.join("") + ".jpeg",
// };
// } catch (error) {
// console.log(error);
// onError && onError(error.message);
// }
// } else {
fileData = {
uri: imageData.localUri || imageData.uri,
type: mimeType,
name: filename,
};
//}
console.log("Got past reading the media.", formData);
formData.append("file", fileData);
formData.append("skip_thumbnail", true);
@@ -101,14 +101,8 @@ export const handleLocalUpload = async ({ ev, context }) => {
}
);
console.log(
"Response Time ",
imexMediaServerResponse.headers["x-response-time"]
);
if (imexMediaServerResponse.status !== 200) {
if (onError) {
console.log(imexMediaServerResponse);
onError(
imexMediaServerResponse.data || imexMediaServerResponse.statusText
);
@@ -118,7 +112,6 @@ export const handleLocalUpload = async ({ ev, context }) => {
onSuccess({
duration: imexMediaServerResponse.headers["x-response-time"],
});
console.log("Succesful upload", imageData.filename);
}
if (callbackAfterUpload) {