fix: 对象复制时对 CopySource 进行 URL 编码以处理特殊字符
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/oss",
|
||||
"version": "0.0.19",
|
||||
"version": "0.0.20",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "bun run bun.config.ts"
|
||||
|
||||
@@ -27,9 +27,10 @@ export const copyObject = async ({ bucketName, newMetadata, objectName, client }
|
||||
const { standardHeaders, customMetadata } = extractStandardHeaders(mergedMeta);
|
||||
|
||||
// 执行复制操作(同一对象,用于更新元数据)
|
||||
// 注意:CopySource 中的 key 必须进行 URL 编码,否则包含特殊字符时会报错
|
||||
const copyCommand = new CopyObjectCommand({
|
||||
Bucket: bucketName,
|
||||
CopySource: `${bucketName}/${objectName}`,
|
||||
CopySource: `${bucketName}/${encodeURIComponent(objectName)}`,
|
||||
Key: objectName,
|
||||
ContentType: standardHeaders.ContentType,
|
||||
CacheControl: standardHeaders.CacheControl,
|
||||
|
||||
@@ -420,7 +420,7 @@ export class OssBase implements OssBaseOperation {
|
||||
async copyObject(sourceObject: string, targetObject: string): Promise<any> {
|
||||
const command = new CopyObjectCommand({
|
||||
Bucket: this.bucketName,
|
||||
CopySource: `${this.bucketName}/${this.prefix}${sourceObject}`,
|
||||
CopySource: `${this.bucketName}/${encodeURIComponent(this.prefix + sourceObject)}`,
|
||||
Key: `${this.prefix}${targetObject}`,
|
||||
});
|
||||
const response = await this.client.send(command);
|
||||
@@ -443,7 +443,7 @@ export class OssBase implements OssBaseOperation {
|
||||
|
||||
const command = new CopyObjectCommand({
|
||||
Bucket: this.bucketName,
|
||||
CopySource: `${this.bucketName}/${key}`,
|
||||
CopySource: `${this.bucketName}/${encodeURIComponent(key)}`,
|
||||
Key: key,
|
||||
ContentType: standardHeaders.ContentType,
|
||||
CacheControl: standardHeaders.CacheControl,
|
||||
|
||||
Reference in New Issue
Block a user