S3 multipart upload for large videos, EISDIR fix
This commit is contained in:
@@ -2,6 +2,10 @@ import {
|
||||
S3Client,
|
||||
PutObjectCommand,
|
||||
DeleteObjectCommand,
|
||||
CreateMultipartUploadCommand,
|
||||
UploadPartCommand,
|
||||
CompleteMultipartUploadCommand,
|
||||
AbortMultipartUploadCommand,
|
||||
} from "@aws-sdk/client-s3";
|
||||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
||||
|
||||
@@ -80,3 +84,69 @@ export async function getPresignedUploadUrl(
|
||||
});
|
||||
return getSignedUrl(s3, command, { expiresIn: expiresInSeconds });
|
||||
}
|
||||
|
||||
export async function createMultipartUpload(
|
||||
key: string,
|
||||
contentType: string,
|
||||
): Promise<{ uploadId: string }> {
|
||||
const s3 = getRustFsClient();
|
||||
const result = await s3.send(
|
||||
new CreateMultipartUploadCommand({
|
||||
Bucket: RUSTFS_BUCKET,
|
||||
Key: key,
|
||||
ContentType: contentType,
|
||||
}),
|
||||
);
|
||||
if (!result.UploadId) {
|
||||
throw new Error("Failed to initiate multipart upload");
|
||||
}
|
||||
return { uploadId: result.UploadId };
|
||||
}
|
||||
|
||||
export async function getPresignedUploadPartUrl(
|
||||
key: string,
|
||||
uploadId: string,
|
||||
partNumber: number,
|
||||
expiresInSeconds = 3600,
|
||||
): Promise<string> {
|
||||
const s3 = getRustFsClient();
|
||||
const command = new UploadPartCommand({
|
||||
Bucket: RUSTFS_BUCKET,
|
||||
Key: key,
|
||||
UploadId: uploadId,
|
||||
PartNumber: partNumber,
|
||||
});
|
||||
return getSignedUrl(s3, command, { expiresIn: expiresInSeconds });
|
||||
}
|
||||
|
||||
export async function completeMultipartUpload(
|
||||
key: string,
|
||||
uploadId: string,
|
||||
parts: { PartNumber: number; ETag: string }[],
|
||||
): Promise<void> {
|
||||
const s3 = getRustFsClient();
|
||||
await s3.send(
|
||||
new CompleteMultipartUploadCommand({
|
||||
Bucket: RUSTFS_BUCKET,
|
||||
Key: key,
|
||||
UploadId: uploadId,
|
||||
MultipartUpload: {
|
||||
Parts: parts.sort((a, b) => a.PartNumber - b.PartNumber),
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function abortMultipartUpload(
|
||||
key: string,
|
||||
uploadId: string,
|
||||
): Promise<void> {
|
||||
const s3 = getRustFsClient();
|
||||
await s3.send(
|
||||
new AbortMultipartUploadCommand({
|
||||
Bucket: RUSTFS_BUCKET,
|
||||
Key: key,
|
||||
UploadId: uploadId,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user