環境細節:
- 作業系統:MacOs Monterey
- Node.js 版本:16
- npm 版本:8.5.1
- @google-cloud/存盤版本:5.18.3
大家好,我在上傳 920Mb 檔案時遇到問題。
當我嘗試通過谷歌存盤的“上傳”功能上傳檔案時,我收到以下錯誤訊息:
"User-Agent":"google-api-nodejs-client/7.14.0","x-goog-api-client":"gl-node/16.13.0 auth/7.14.0","Accept":"application/json"},"responseType":"json"},"code":400,"errors":[{"message":"Cannot insert legacy ACL for an object when uniform bucket-level access is enabled. Read more at https://cloud.google.com/storage/docs/uniform-bucket-level-access","domain":"global","reason":"invalid"}],"errorMessage":"Cannot insert legacy ACL for an object when uniform bucket-level access is enabled. Read more at https://cloud.google.com/storage/docs/uniform-bucket-level-access","errorStack":"Error: Cannot insert legacy ACL for an object when uniform bucket-level access is enabled. Read more at https://cloud.google.com/storage/docs/uniform-bucket-level-access\n at Gaxios._request (/Users/lucascognamiglio/Desktop/CherryProjects/epona-ape/node_modules/gaxios/build/src/gaxios.js:129:23)\n at runMicrotasks (<anonymous>)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async JWT.requestAsync (/Users/lucascognamiglio/Desktop/CherryProjects/epona-ape/node_modules/google-auth-library/build/src/auth/oauth2client.js:368:18)\n at async Upload.makeRequest (/Users/lucascognamiglio/Desktop/CherryProjects/epona-ape/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload/index.js:605:21)\n at async Upload.getAndSetOffset (/Users/lucascognamiglio/Desktop/CherryProjects/epona-ape/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload/index.js:552:26)\n at async Upload.continueUploading (/Users/lucascognamiglio/Desktop/CherryProjects/epona-ape/node_modules/@google-cloud/storage/build/src/gcs-resumable-upload/index.js:350:9)"}
這只發生在我嘗試上傳這種大小的檔案時,而如果我嘗試上傳圖片,我沒有任何問題。

為了更清楚,我附上了代碼的一部分:
const tempFolder = await tmp.dir({ unsafeCleanup: true });
const destinationPathFile = `${tempFolder.path}/${fileName}`;
const downloaded = await this.download(fileURL, destinationPathFile);
if (downloaded) {
const uploadResponse = await getStorage().bucket('bucket-name').upload(destinationPathFile, {
destination: newFileName,
gzip: true,
metadata: {
cacheControl: 'public, max-age=31536000',
},
public: isPublic,
});
log.info(`FileService => upload => Upload finished for file ${fileURL} with name ${newFileName}`);
if (uploadResponse) {
const metadata = uploadResponse[1];
return metadata.mediaLink;
}
}
await tempFolder.cleanup();
} catch (error) {
log.info(`FileService => upload => Error for file ${fileURL} with name ${newFileName}`, error);
}
uj5u.com熱心網友回復:
什么大小的物件都沒有關系,您應該收到相同的錯誤。
啟用統一存盤桶級訪問時,您不能特殊物件 ACL。
更改您的代碼以不指定 ACL(洗掉公共:isPublic):
const uploadResponse = await getStorage().bucket('bucket-name').upload(destinationPathFile, {
destination: newFileName,
gzip: true,
metadata: {
cacheControl: 'public, max-age=31536000'
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/456170.html
