1.3.6-3 Test Build - Refactor local uploads to go in bulk.
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import axios from "axios";
|
||||
import * as ImageManipulator from "expo-image-manipulator";
|
||||
import * as MediaLibrary from "expo-media-library";
|
||||
import mime from "mime";
|
||||
import { store } from "../redux/store";
|
||||
import mime from "mime";
|
||||
import * as MediaLibrary from "expo-media-library";
|
||||
|
||||
axios.interceptors.request.use(
|
||||
function (config) {
|
||||
@@ -29,9 +28,14 @@ axios.interceptors.response.use(
|
||||
}
|
||||
);
|
||||
|
||||
export const handleLocalUpload = async ({ ev, context }) => {
|
||||
const { onError, onSuccess, onProgress, filename, mediaId } = ev;
|
||||
const { jobid, invoice_number, vendorid, callbackAfterUpload } = context;
|
||||
export const handleLocalUpload = async ({
|
||||
files,
|
||||
onError,
|
||||
onSuccess,
|
||||
onProgress,
|
||||
context,
|
||||
}) => {
|
||||
const { jobid } = context;
|
||||
const bodyshop = store.getState().user.bodyshop;
|
||||
try {
|
||||
var options = {
|
||||
@@ -41,26 +45,22 @@ export const handleLocalUpload = async ({ ev, context }) => {
|
||||
},
|
||||
onUploadProgress: (e) => {
|
||||
if (onProgress)
|
||||
onProgress({ percent: (e.loaded / e.total) * 100, loaded: e.loaded });
|
||||
onProgress({ percent: e.loaded / e.total, loaded: e.loaded });
|
||||
},
|
||||
};
|
||||
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append("jobid", jobid);
|
||||
if (invoice_number) {
|
||||
formData.append("invoice_number", invoice_number);
|
||||
formData.append("vendorid", vendorid);
|
||||
}
|
||||
const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
|
||||
const mimeType = mime.getType(imageData.uri);
|
||||
// const imageData = await MediaLibrary.getAssetInfoAsync(mediaId);
|
||||
// const mimeType = mime.getType(imageData.uri);
|
||||
|
||||
//let thumb;
|
||||
let fileData = {
|
||||
uri: null,
|
||||
type: null,
|
||||
name: null,
|
||||
};
|
||||
// //let thumb;
|
||||
// let fileData = {
|
||||
// uri: null,
|
||||
// type: null,
|
||||
// name: null,
|
||||
// };
|
||||
// if (mimeType === "image/heic") {
|
||||
// try {
|
||||
// thumb = await ImageManipulator.manipulateAsync(imageData.uri, [], {
|
||||
@@ -80,25 +80,37 @@ export const handleLocalUpload = async ({ ev, context }) => {
|
||||
// onError && onError(error.message);
|
||||
// }
|
||||
// } else {
|
||||
fileData = {
|
||||
uri: imageData.localUri || imageData.uri,
|
||||
type: mimeType,
|
||||
name: filename,
|
||||
};
|
||||
// fileData = {
|
||||
// uri: imageData.localUri || imageData.uri,
|
||||
// type: mimeType,
|
||||
// name: filename,
|
||||
// };
|
||||
//}
|
||||
|
||||
formData.append("file", fileData);
|
||||
const filesList = [];
|
||||
for (const file of files) {
|
||||
const imageData = await MediaLibrary.getAssetInfoAsync(file.id);
|
||||
const mimeType = mime.getType(imageData.uri);
|
||||
filesList.push({
|
||||
uri: imageData.localUri || imageData.uri,
|
||||
type: mimeType,
|
||||
name: imageData.filename,
|
||||
});
|
||||
formData.append("file", {
|
||||
uri: imageData.localUri || imageData.uri,
|
||||
type: mimeType,
|
||||
name: imageData.filename,
|
||||
});
|
||||
}
|
||||
|
||||
//formData.append("file", files);
|
||||
formData.append("skip_thumbnail", true);
|
||||
|
||||
try {
|
||||
const imexMediaServerResponse = await axios.post(
|
||||
`${bodyshop.localmediaserverhttp}/${
|
||||
invoice_number ? "bills" : "jobs"
|
||||
}/upload`,
|
||||
`${bodyshop.localmediaserverhttp}/jobs/upload`,
|
||||
formData,
|
||||
{
|
||||
...options,
|
||||
}
|
||||
options
|
||||
);
|
||||
|
||||
if (imexMediaServerResponse.status !== 200) {
|
||||
@@ -113,10 +125,6 @@ export const handleLocalUpload = async ({ ev, context }) => {
|
||||
duration: imexMediaServerResponse.headers["x-response-time"],
|
||||
});
|
||||
}
|
||||
|
||||
if (callbackAfterUpload) {
|
||||
callbackAfterUpload();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error uploading documents:", error);
|
||||
onError && onError(error.message);
|
||||
|
||||
Reference in New Issue
Block a user