ini
This commit is contained in:
24
src/core/copy-object.ts
Normal file
24
src/core/copy-object.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Client, CopyDestinationOptions, CopySourceOptions } from 'minio';
|
||||
|
||||
type CopyObjectOpts = {
|
||||
bucketName: string;
|
||||
newMetadata: Record<string, string>;
|
||||
prefix: string;
|
||||
client: Client;
|
||||
};
|
||||
/**
|
||||
* 复制对象 REPLACE 替换
|
||||
* @param param0
|
||||
* @returns
|
||||
*/
|
||||
export const copyObject = async ({ bucketName, newMetadata, prefix, client }: CopyObjectOpts) => {
|
||||
const source = new CopySourceOptions({ Bucket: bucketName, Object: prefix });
|
||||
const destination = new CopyDestinationOptions({
|
||||
Bucket: bucketName,
|
||||
Object: prefix,
|
||||
UserMetadata: newMetadata,
|
||||
MetadataDirective: 'REPLACE',
|
||||
});
|
||||
const copyResult = await client.copyObject(source, destination);
|
||||
return copyResult;
|
||||
};
|
||||
Reference in New Issue
Block a user