Skip to content
Snippets Groups Projects
Verified Commit dc2060fa authored by Daniel Göbel's avatar Daniel Göbel
Browse files

Abort a multipart upload if it fails

parent b48cfd7d
No related branches found
No related tags found
1 merge request!110Resolve "List Multipart Uploads and abort them"
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import type { _Object as S3Object, HeadObjectOutput } from "@aws-sdk/client-s3"; import type { _Object as S3Object, HeadObjectOutput } from "@aws-sdk/client-s3";
import { import {
AbortMultipartUploadCommand,
CopyObjectCommand, CopyObjectCommand,
GetObjectCommand, GetObjectCommand,
HeadObjectCommand, HeadObjectCommand,
...@@ -237,7 +238,23 @@ export const useS3ObjectStore = defineStore({ ...@@ -237,7 +238,23 @@ export const useS3ObjectStore = defineStore({
if (onProgress != undefined) { if (onProgress != undefined) {
parallelUploads3.on("httpUploadProgress", onProgress); parallelUploads3.on("httpUploadProgress", onProgress);
} }
await parallelUploads3.done(); try {
await parallelUploads3.done();
} catch (e) {
// if there is an error with the multipart upload, send an abort multipart upload command
const uploadObject = JSON.parse(JSON.stringify(parallelUploads3));
if (uploadObject["isMultiPart"] && uploadObject["uploadId"]) {
await this.client.send(
new AbortMultipartUploadCommand({
// AbortMultipartUploadRequest
Bucket: bucketName, // required
Key: key, // required
UploadId: uploadObject["uploadId"], // required
}),
);
}
throw e;
}
const newObj = { const newObj = {
Key: key, Key: key,
Size: file.size ?? 0, Size: file.size ?? 0,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment