Skip to content

Commit

Permalink
Merge pull request #225 from bcgov/upload
Browse files Browse the repository at this point in the history
allow file upload process to create new version of file if it exiists
  • Loading branch information
TimCsaky authored Dec 9, 2024
2 parents 3fc8bfd + a471487 commit d5ba853
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit d5ba853

Please sign in to comment.