Skip to content

Commit

Permalink
feat(in-app/v1): safe create object url
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjdd committed Mar 20, 2024
1 parent 0712722 commit db374dc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions in-app/v1/src/utils/useUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function useUpload({ onError }: UseUploadOptions = {}): UseUploadResult {
const fileInfo: FileInfo<number> = {
key,
name: file.name,
url: URL.createObjectURL(file),
url: createObjectURL(file),
progress: 0,
};

Expand Down Expand Up @@ -80,7 +80,7 @@ export function useUpload({ onError }: UseUploadOptions = {}): UseUploadResult {
.then((file) => {
update({
id: file.id,
// url: file.url,
url: fileInfo.url ?? file.url,
mime: file.mime,
progress: undefined,
});
Expand All @@ -102,3 +102,9 @@ export function useUpload({ onError }: UseUploadOptions = {}): UseUploadResult {

return { files, isUploading: uploadingCount > 0, upload, remove, removeAll };
}

function createObjectURL(obj: Blob) {
if (typeof URL === 'function' && typeof URL.createObjectURL === 'function') {
return URL.createObjectURL(obj);
}
}

0 comments on commit db374dc

Please sign in to comment.