Home > Back-end >  "Cannot insert legacy ACL for an object when uniform bucket-level access" only for large f
"Cannot insert legacy ACL for an object when uniform bucket-level access" only for large f

Time:04-06

Environment details:

  • OS: MacOs Monterey
  • Node.js version: 16
  • npm version: 8.5.1
  • @google-cloud/storage version: 5.18.3

Hi everyone, I'm having a problem uploading a 920Mb file.

When I try to upload the file via google storage's "upload" function, I get this error message:

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

This only happens to me when I try to upload a file of this size, while if I try to upload an image, I don't have any kind of problem.

enter image description here

For greater clarity I am attaching the part of the code:

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

CodePudding user response:

It does not matter what size object, you should have received the same error.

You cannot special object ACLs when uniform bucket-level access is enabled.

Change your code to not specify an ACL (delete public: isPublic):

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