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

add operation to abort multipart upload #784

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions lib/controllers/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,20 @@ exports.uploadPartCopy = async function uploadPartCopy(ctx) {
throw err;
}
};

/**
* Abort Multipart Upload
* This action aborts a multipart upload. After a multipart upload is aborted,
* no additional parts can be uploaded using that upload ID. The storage
* consumed by any previously uploaded parts will be freed.
* {@link https://docs.aws.amazon.com/AmazonS3/latest/API/API_AbortMultipartUpload.html}
*/
exports.abortMultipartUpload = async function abortMultipartUpload(ctx) {
await ctx.store.abortUpload(
ctx.params.bucket,
ctx.params.key,
ctx.query.uploadId,
ctx.headers,
Comment on lines +815 to +819

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why to pass unused (key & headers) ?

);
ctx.body = '';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need to set status too (204)

};
2 changes: 2 additions & 0 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ router
switch (ctx.params.queryMethod) {
case undefined:
return objectCtrl.deleteObject(ctx);
case 'uploadId':
return objectCtrl.abortMultipartUpload(ctx);
case 'tagging':
throw new S3Error('NotImplemented');
default:
Expand Down
9 changes: 9 additions & 0 deletions lib/stores/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,15 @@ class FilesystemStore {
]);
}

async abortUpload(bucket, key, uploadId, metadata) {
const uploadDir = path.join(
this.getResourcePath(bucket, undefined, 'uploads'),
uploadId,
);

await fs.rmdir(uploadDir, { recursive: true });
}

async putPart(bucket, uploadId, partNumber, content) {
const partPath = path.join(
this.getResourcePath(bucket, undefined, 'uploads'),
Expand Down
18 changes: 17 additions & 1 deletion test/controllers/object.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ describe('Operations on Objects', () => {
});
});

describe('Initiate/Upload/Complete Multipart upload', () => {
describe('Initiate/Upload/Complete/Abort Multipart upload', () => {
it('uploads a text file to a multi directory path', async function () {
const data = await s3Client
.putObject({
Expand Down Expand Up @@ -1555,6 +1555,22 @@ describe('Operations on Objects', () => {
expect(JSON.parse(data.CopyPartResult.ETag)).to.be.ok;
});

it('aborts a multipart upload', async function () {
const upload = await s3Client
.createMultipartUpload({
Bucket: 'bucket-a',
Key: 'destination',
})
.promise();
await s3Client
.abortMultipartUpload({
Bucket: 'bucket-a',
Key: 'desintation',
UploadId: upload.UploadId,
})
.promise();
});

it('fails to copy a part range for an out of bounds requests', async function () {
const upload = await s3Client
.createMultipartUpload({
Expand Down