Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow file upload process to create new version of file if it exists #225

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion frontend/src/components/object/ObjectUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ const onUpload = async (event: any) => {

const data = formData.find((x: ObjectMetadataTagFormType) => x.filename === file.name);

await objectStore.createObject(
const response = await objectStore.createObject(
file,
{ metadata: data?.metadata },
{ bucketId: bucketId, tagset: data?.tagset },
{ timeout: 0 } // Infinite timeout for big files upload to avoid timeout error
);

// show toast for any object updates
if (response?.newVersionId) toast.info(
`A new version of file '${file.name}' has been created`,'', { life: 0 });

successfulFiles.value.push(file);
} catch (error: any) {
toast.error(`Failed to upload file ${file.name}`, error, { life: 0 });
Expand Down
16 changes: 14 additions & 2 deletions frontend/src/store/objectStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,20 @@ export const useObjectStore = defineStore('object', () => {
await objectService.createObject(object, headers, params, axiosOptions);
} catch(error: any) {
if (error.response?.status === 409){
throw new Error(error.response.data.detail);
} else {
// New behaviour:
// if file already exists in bucket
// do updateObject operation instead
const newVersionId = await updateObject(
error.response.data.existingObjectId,
object,
headers,
params,
axiosOptions
);
return { newVersionId: newVersionId };
}

else {
throw new Error('Network error');
}
} finally {
Expand Down
Loading