"Cannot insert legacy ACL for an object when uniform bucket-level access" 仅适用于大文件

"Cannot insert legacy ACL for an object when uniform bucket-level access" only for large file

环境详细信息:

大家好,我在上传 920Mb 文件时遇到问题。

当我尝试通过 google 存储的“上传”功能上传文件时,我收到此错误消息:

"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);
}

无论对象大小如何,您都应该收到相同的错误。

启用统一 bucket-level 访问时,您不能使用特殊对象 ACL。

更改您的代码以不指定 ACL(删除 public: isPublic):

const uploadResponse = await getStorage().bucket('bucket-name').upload(destinationPathFile, {
    destination: newFileName,
    gzip: true,
    metadata: {
         cacheControl: 'public, max-age=31536000'
     }    
});