nodejs-storage: Rename storage objects returns 404 Not Found

Hi. This feature over here for renaming GCS Objects is not working for me. Is this still active? I keep getting 404 Not found whereas I verified all my resources are present and I’m using correct paths and credentials.

Also, found mistake in documentation - you are using a different variable name in comments guide here and different in actual code over here.

Environment details

  • Node.js version: v14
  • npm version: v6
  • @google-cloud/storage version: ^5.8.5

Steps to reproduce

  1. I used this template - here. I’m trying to rename an existing file in same bucket.

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Woo! Glad we got it figured out. Sorry for the confusion!

Thank you for taking the time to do that. The issue is how bucketName is defined. To get the folder name, pass that into the file() and move() methods. Could you try it with these changes?

//Import all files
async function rename(){
    //GCS Data Source
-   const bucketName = 'bucket-name/folder-name';   //folder-name is in format `TEST.FOLDER`
+   const bucketName = 'bucket-name';   //folder-name is in format `TEST.FOLDER`

// Import the Google Cloud client libraries
    const {Storage} = require('@google-cloud/storage');

// Instantiate BigQuery and Storage clients
    let projectId = require("../../credential-file.json").project_id;
    const storage = new Storage({
        keyFilename: "../../credential-file.json",
        projectId: projectId
    });

-   let destFileName = `test-2`;
+   let destFileName = `folder-name/test-2`;
-   await storage.bucket(bucketName).file('test-env-data-000000000000').move(destFileName);
+   await storage.bucket(bucketName).file('folder-name/test-env-data-000000000000').move(destFileName);
}

rename().catch(e => console.log(e));