-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
abortMultipartUpload.ts
62 lines (55 loc) · 1.55 KB
/
abortMultipartUpload.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import {
Endpoint,
HttpRequest,
HttpResponse,
parseMetadata,
} from '@aws-amplify/core/internals/aws-client-utils';
import { composeServiceApi } from '@aws-amplify/core/internals/aws-client-utils/composers';
import { MetadataBearer } from '@aws-sdk/types';
import type { AbortMultipartUploadCommandInput } from './types';
import { defaultConfig } from './base';
import {
parseXmlError,
s3TransferHandler,
serializePathnameObjectKey,
} from './utils';
export type AbortMultipartUploadInput = Pick<
AbortMultipartUploadCommandInput,
'Bucket' | 'Key' | 'UploadId'
>;
export type AbortMultipartUploadOutput = MetadataBearer;
const abortMultipartUploadSerializer = (
input: AbortMultipartUploadInput,
endpoint: Endpoint
): HttpRequest => {
const url = new URL(endpoint.url.toString());
url.pathname = serializePathnameObjectKey(url, input.Key);
url.search = new URLSearchParams({
uploadId: input.UploadId,
}).toString();
return {
method: 'DELETE',
headers: {},
url,
};
};
const abortMultipartUploadDeserializer = async (
response: HttpResponse
): Promise<AbortMultipartUploadOutput> => {
if (response.statusCode >= 300) {
const error = await parseXmlError(response);
throw error;
} else {
return {
$metadata: parseMetadata(response),
};
}
};
export const abortMultipartUpload = composeServiceApi(
s3TransferHandler,
abortMultipartUploadSerializer,
abortMultipartUploadDeserializer,
{ ...defaultConfig, responseType: 'text' }
);