GeezerVison is showing github.com — storage: Support for folders · Issue #337 · googleapis/google-cloud-node
storage: Support for folders #337Labels 🚨This issue needs some love.api: storageIssues related to the Cloud Storage API.triage meI really want to be triaged. DescriptionHi,
Is it possible to upload a file into a folder ?
Thanks Activitycristiano-belloni commented on Dec 22, 2014 Hi @pierre-b,
what happens if you do yourBucket.file('myFolderName/myFileName')? It should just work. pierre-b commented on Dec 22, 2014 Yes @janesconference it works with the createWriteStream function, but not with the bucket.upload one:
bucket.upload(sourcePath, options, function(error, file) {
});cristiano-belloni commented on Dec 22, 2014 Never tried it, so take it with a grain of salt, but you can try:
bucket.upload(encodeURIComponent('myFolderName/myFileName'), options, function(error, file) { });
pierre-b commented on Dec 22, 2014 I think it should be added to the upload() by default, like in S3. ryanseys commented on Dec 22, 2014 I agree. Did you try that and it worked? stephenplusplus commented on Dec 22, 2014 @pierre-b can you paste the code you used to upload the file, as well as what version of gcloud you're using? stephenplusplus commented on Dec 22, 2014 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. Reacted by Jaskeerat Singh Randhawa Reacted by Ulises Manuel Vargas De Sousa changed the title [-]Support for folders[/-] [+]storage: Support for folders[/+] on Dec 22, 2014ryanseys commented on Dec 23, 2014 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? pierre-b commented on Dec 24, 2014 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) {})cristiano-belloni commented on Dec 24, 2014 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. stephenplusplus commented on Jan 5, 2015 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.
MetadataMetadata🚨This issue needs some love.api: storageIssues related to the Cloud Storage API.triage meI really want to be triaged. DevelopmentNo branches or pull requestsIssue actions
|