Repository navigation
storage: Support for folders #337
Description
Activity
Hi @pierre-b,
what happens if you doyourBucket.file('myFolderName/myFileName')? It should just work.Yes @janesconference it works with the createWriteStream function, but not with the bucket.upload one:
bucket.upload(sourcePath, options, function(error, file) { });
Never tried it, so take it with a grain of salt, but you can try:
bucket.upload(encodeURIComponent('myFolderName/myFileName'), options, function(error, file) { });I think it should be added to the upload() by default, like in S3.
I agree. Did you try that and it worked?
@pierre-b can you paste the code you used to upload the file, as well as what version of gcloud you're using?
To elaborate more,
uploadcan 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
uploadmethod 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.uploaddoesn'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.
Reacted by Jaskeerat Singh RandhawaReacted by Ulises Manuel Vargas De SousaCan confirm that using the
destinationoption 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?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) {})
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
localis my local file name ( ie:'/mylocalpath/myfile') andremoteis my remote file path ( ie:'remotepath/myfile'), both without any encoding.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.
- addedapi: storageIssues related to the Cloud Storage API.Issues related to the Cloud Storage API.
on Feb 2, 2015 34 remaining items
- added 2 commits that reference this issue
on Feb 3, 2026 - added 2 commits that reference this issue
on Feb 24, 2026 - added a commit that references this issue
on Feb 25, 2026 - added a commit that references this issue
on Feb 26, 2026 - added a commit that references this issue
on Mar 5, 2026 - added 2 commits that reference this issue
on Mar 11, 2026 - added a commit that references this issue
on Mar 18, 2026
Hi,
Is it possible to upload a file into a folder ?
Thanks