-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support uploading directories #492
support uploading directories #492
Conversation
@ryanseys - If you can take a quick look at the first post to see if this is a useful addition, I'll start working on the tests for these to get it ready for code review & merge. |
Yes this looks ok. What approach is taken when filenames conflict. E.g. I'm thinking maybe we don't even need Sorry if this doesn't make sense. |
Or just always maintain structure when given a directory. If given a glob, always flatten. Seems reasonable. |
I think that's probably what you're doing already except it's strewn across upload and uploadDirectory where I'm not convinced we need both. |
The last one will win.
I like this! |
If it makes the logic of upload infinitely more difficult, I'd say it's not worth it, so if this is already effectively doing the same thing as:
then I don't see any reason to change it now. But if it's easy to change, that'd be cool :) |
I played around with it for a bit, but I couldn't find a way to make the change elegantly. For now, I'll continue with the two methods ( |
No worries. Might be beneficial and more intuitive for the users anyway. At On Thursday, April 16, 2015, Stephen Sawchuk [email protected]
|
ed8e354
to
4be2902
Compare
Ready for a closer look 👓 |
}; | ||
}); | ||
|
||
async.parallelLimit(uploadFileFns, MAX_PARALLEL_UPLOADS, function() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
(cont'd from #492 (comment)) After much thought and attempts to implement this, I don't think we need to support uploading directories or globs. It's quite straightforward for a user to implement uploading a directory in their app: var async = require("async")
var fs = require("fs")
var storage = require("gcloud")
var myBucket = gcloud.storage().bucket("pics")
uploadDirectory(myBucket, "/Users/stephen/Photos", function (err, files) {})
function uploadDirectory(bucket, directory, callback) {
fs.readdir(directory, function (err, files) {
async.map(files, bucket.upload, callback)
})
} If they want other things to happen, like uploading the files into a new directory in their bucket, recursing through child directories and maintaining that hierarchy, etc., their code is the best place to handle that. Our supporting it It leads to either too much guess work or confusing options. |
Globs I agree are a little fancy and require weird options but just On Monday, April 20, 2015, Stephen Sawchuk [email protected] wrote:
|
Sure, your code has yet to leave me unimpressed! |
I still think this is outside the scope of what our lib should support. We allow uploading files via @ryanseys with all of your free time, if you're still interesting in taking a stab at a smaller implementation of this, please feel free :) |
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@types/tmp](https://togithub.com/DefinitelyTyped/DefinitelyTyped) | [`0.2.1` -> `0.2.2`](https://renovatebot.com/diffs/npm/@types%2ftmp/0.2.1/0.2.2) | [![age](https://badges.renovateapi.com/packages/npm/@types%2ftmp/0.2.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/@types%2ftmp/0.2.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/@types%2ftmp/0.2.2/compatibility-slim/0.2.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/@types%2ftmp/0.2.2/confidence-slim/0.2.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Configuration 📅 **Schedule**: "after 9am and before 3pm" (UTC). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/nodejs-dns).
Fixes #412
To Dos
This is a work in progress, but is an attempt to make a sane API for uploading directories.
Globs
bucket.uploadDirectory
is a wrapper aroundbucket.upload
, which now supports globs:Note that the resulting file names aren't prefixed with a directory path (e.g. "chipmunks/chipmunk-1.jpg" vs "chipmunk-1.jpg"). Since a glob can include several files and directories in various locations on a hard drive, by default, just the filename is used as the uploaded file's name.
By specifying
options.basePath
, a user can tell us the common parent of all of the locations their glob matches, which is then used as a prefix for the file. This is howbucket.uploadDirectory
works (simplified):Extending globs
bucket.upload accepts either a single glob or array of globs. It's passed directly to sindresorhus/globby, which uses isaacs/minimatch and isaacs/node-glob to return the matching paths. All minimatch glob patterns are accepted, as well as node-glob options via
options.globOptions
.