Skip to content

storage: Support for folders #337

Description

@pierre-b

Hi,

Is it possible to upload a file into a folder ?

Thanks

Activity

  1. cristiano-belloni commented on Dec 22, 2014

    @cristiano-belloni
    Contributor

    Hi @pierre-b,
    what happens if you do yourBucket.file('myFolderName/myFileName')? It should just work.

  2. pierre-b commented on Dec 22, 2014

    @pierre-b
    Author

    Yes @janesconference it works with the createWriteStream function, but not with the bucket.upload one:

    bucket.upload(sourcePath, options, function(error, file) {
    });
  3. cristiano-belloni commented on Dec 22, 2014

    @cristiano-belloni
    Contributor

    Never tried it, so take it with a grain of salt, but you can try:

    bucket.upload(encodeURIComponent('myFolderName/myFileName'), options, function(error, file) { });

  4. pierre-b commented on Dec 22, 2014

    @pierre-b
    Author

    I think it should be added to the upload() by default, like in S3.

  5. ryanseys commented on Dec 22, 2014

    @ryanseys
    Contributor

    I agree. Did you try that and it worked?

  6. stephenplusplus commented on Dec 22, 2014

    @stephenplusplus
    Contributor

    @pierre-b can you paste the code you used to upload the file, as well as what version of gcloud you're using?

  7. stephenplusplus commented on Dec 22, 2014

    @stephenplusplus
    Contributor

    To elaborate more, upload can be called a few different ways, but the most simple is probably:

    myBucket.upload("/Users/stephen/Desktop/photo.jpg", function (err, file) {})

    In this case, I didn't specify anything about the destination file, only that I want one to be created based on the file at "/Users/stephen/Desktop/photo.jpg". The upload method will detect the file name as being "photo.jpg", and will drop it in your bucket with the same name and the contents at the given file path.

    upload doesn't treat your local file system's hierarchy as being identical to your bucket's hierarchy, so it needs to be told explicitly where you wish the file to end up:

    myBucket.upload("/Users/stephen/Desktop/photo.jpg", {
      destination: myBucket.file("my-photos/photo.jpg")
    }, function (err, file) {})

    Now the file should end up inside a directory called "my-photos", named "photo.jpg". If you were using it this way, and it's not working, that's a bug we need to squash.

  8. changed the title [-]Support for folders[/-] [+]storage: Support for folders[/+] on Dec 22, 2014
  9. ryanseys commented on Dec 23, 2014

    @ryanseys
    Contributor

    Can confirm that using the destination option and providing a file object like suggested above will correctly upload the file into a folder. @pierre-b Can you confirm this also works for you?

  10. pierre-b commented on Dec 24, 2014

    @pierre-b
    Author

    Using v0.11.0 the following doesn't work too, the file is not saved in the folder:

    myBucket.upload("/Users/stephen/Desktop/photo.jpg", {
      destination: myBucket.file("my-photos/photo.jpg")
    }, function (err, file) {})
  11. cristiano-belloni commented on Dec 24, 2014

    @cristiano-belloni
    Contributor

    This is working for me on v0.12.0,

    return resourceBucket.upload(
            local,
            {
                destination: remote,
                metadata: { contentType: contentType }
            }, function (err, file) {
                if (cb) {
                    cb(err, file);
                }
            });
    

    Where local is my local file name ( ie: '/mylocalpath/myfile' ) and remote is my remote file path ( ie: 'remotepath/myfile' ), both without any encoding.

  12. stephenplusplus commented on Jan 5, 2015

    @stephenplusplus
    Contributor

    Going to close as all signs point to this working. If you still can't get it working, feel free to re-open with more details. If you have ideas for how we can improve the documentation or API to make a better experience for others, those are always welcome as well.

  13. 34 remaining items

  14. added a commit that references this issue on Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

🚨This issue needs some love.api: storageIssues related to the Cloud Storage API.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions