Skip to content

Commit

Permalink
Fix upload for Android platform
Browse files Browse the repository at this point in the history
  • Loading branch information
adimiz1 authored Mar 25, 2024
1 parent 907cc0b commit facdd40
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/api/upload/src/uploader_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,32 @@ function buildUrl({prefix, apiVersion, cloudName, resourceType, action}: UrlPara
function buildPayload(file: string | undefined, options: UploadApiOptions) {
const data = new FormData();
if(file != undefined) {
data.append('file', {name: "file", uri: file});
data.append('file', {name: "file", uri: file, type: setMimeType(options.resource_type)});
}

for (const key in options) {
data.append(key, options[key]);
}
return data;
}

function setMimeType(resource_type: 'image' | 'video' | 'raw' | 'auto' | undefined) {
switch(resource_type) {
case 'image':
return 'image/*';
case 'video':
return 'video/*';
case 'raw':
return '*/*';
case 'auto':
return '*/*';
case undefined:
return 'image/*';
default:
return 'image/*';
}
}

function parseApiResponse(response: any): UploadApiResponse | UploadApiErrorResponse {
// Check if the response has a "message" property to determine the error response

Expand Down

0 comments on commit facdd40

Please sign in to comment.