GeezerVison is showing github.com — support globs in `upload` · Issue #412 · googleapis/google-cloud-node
support globs in upload #412Labels 🚨This issue needs some love.api: storageIssues related to the Cloud Storage API.triage meI really want to be triaged. DescriptionI have error Error: EISDIR
Is it relevance with upload folder features?
Can I request that feature? if not, could you explain me why?
Thanks Activityryanseys commented on Feb 24, 2015 Thanks for your suggestion! I believe we may be able to support such a feature. Something like this might be sufficient:
var opts = { recursive: true, validation: true, resumable: true };
bucket.uploadFolder('./photos', opts, function(errs, files) {
// errs is null if no errors occur on any files
// errs is array of errors for every file that fails to upload
// files is every file that succeeds in uploading
});
The only issue I can see with this is that it will be hard to measure progress of such uploads (which could be long running) without any sort of stream interface. We might be able to do some sort of "progress stream" like:
var progress = bucket.uploadFolder(/* ... */);
progress.on('error', errCallback);
progress.on('fileEnd', aSingleFileDoneCallback);
progress.on('end', allFilesDoneCallback);
Until then you could probably get by with something like this which should in theory upload all files in a particular folder (non-recursively):
var fs = require('fs');
var async = require('async'); // npm install async
var bucket = storage.bucket('my-bucket'); // need to inititialize storage beforehand (see docs)
var contents = fs.readdirSync('./path/to/folder'); // get contents of folder (files and folders)
var files = contents.filter(function(file) {
return fs.statSync(file).isFile(); // filter out only files
});
async.each(files, function(file, cb) {
bucket.upload(file, cb);
}, function(err) {
// all files should be uploaded now assuming there were no errors!
});stephenplusplus commented on Feb 24, 2015 I don't mind the idea, though we would just be doing what the user could do in their code (1. get a list of files in a directory, 2. send each file to bucket.upload).
To handle this more easily, we could support glob input to allow more specificity: bucket.upload("backups/*.jpg", ... stephenplusplus commented on Feb 24, 2015
The only issue I can see with this is that it will be hard to measure progress of such uploads (which could be long running) without any sort of stream interface.
That example looks good to me, though I would nit-pickingly change fileEnd to file-uploaded. ryanseys commented on Feb 24, 2015 Yeah, sure! That was just an example 😃 If it happened that way we might decide to have more events too. raitucarp commented on Feb 24, 2015 changed the title [-]Add support to upload folder?[/-] [+]support globs in `upload`[/+] on Mar 31, 2015stephenplusplus commented on Jun 8, 2015 I got it in my head that supporting globs would be a good idea, but after an attempt at an implementation, it felt like more weight than our library should handle. If anyone objects, feel free to discuss!
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
|