-
Notifications
You must be signed in to change notification settings - Fork 369
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
transferManager.downloadManyFiles not writing files locally #2200
Comments
Hi @hochoy thanks for opening this issue! We have been interested in hearing feedback about Regarding the first issue you raised about nothing being written when there is no prefix this was the intended design (and not saying it is necessarily the best). As you noted / saw under the hood As for the second issue this is a good catch and I think the fix looks good. I will just do some local testing to verify. Please feel free to take your PR out of draft state if you feel it is ready for review and I will comment there accordingly. We much appreciate the contribution. |
Thank you, did not expect such a prompt reply. I'll take it out of draft. - done ✅ Regarding your first issue comment, I had suspected that might have been the intent. Writing files to the local machine can often be undesirable to the user of the
EDITED: Correction, it looks like I could just |
Hey there, any movement on this? As is, it doesn't look like you can use |
This API is confusing. The response object gives you const localPath = path.resolve(process.cwd(), `dest`);
const downloadRes = await transferManager.downloadManyFiles('active', {
// passthroughOptions: {
// destination: localPath,
// },
});
if (Array.isArray(downloadRes)) {
downloadRes.map((res, idx) => {
writeFileSync(path.resolve(localPath, `file-${idx}`), res[0]);
});
} The documentation and code example do not help much. For those who want to download multiple files, I would suggest the humble const [files] = await storage.bucket(bucketName).getFiles({ prefix: 'folder' });
console.log('files', files);
// make directories
files
.filter((f) => f.name.endsWith('/'))
.forEach((dir) => {
const folder = path.resolve(localPath, dir.name);
if (!existsSync(folder)) {
mkdirSync(folder, { recursive: true });
}
});
// download files
const res = await Promise.all(
files
.filter((f) => !f.name.endsWith('/'))
.map(async (f) => {
const destination = path.resolve(localPath, f.name);
await client.file(f.name).download({ destination });
}),
); Concerns
In Python sdk there is a similar API called https://cloud.google.com/storage/docs/samples/storage-transfer-manager-download-bucket |
Hi @stabback and @convers39 I will circle back on this and try and pick up where the previous PR left off. I will update accordingly. |
Hey @ddelgrosso1, sorry for commenting on a closed issue, but I'm running into the same issue in I've got two folders, each with subfolders, in storage, with files in each. I'm calling UpdateI wound up deleting the parent folder in Storage of that was causing download errors and recreating it, and downloading works now as expected. I'm not sure if the problem was Storage-side or client-side. |
@Snugug if you hit the same problem again would you mind opening a new issue so that I can take a look / resolve it? |
Issue summary
I hesitated to split this into 2 issues because they are rather tightly coupled
prefix
is not set,transferManager.downloadManyFiles
does not actually write files locally. This is becausedestination
isundefined
.prefix
is set,file.download(...)
attempts to write the file, but is unable to recursively create directory structure on local machine.Proposed draft PR
#2199
Standard questions
Environment details
@google-cloud/storage
version: 6.10.1Steps to reproduce
Issue 1:
prefix
destination
is undefined. The draft PR contains a suggestion to always generate the destination.Issue 2:
prefix
This is due to the file stream at
nodejs-storage/src/file.ts
Lines 2108 to 2111 in fe9e3a4
Thanks, it is my first issue and fork of the repo! Open to feedback. I've already signed the CLA, but kept the PR as draft until the codeowner reviews the issue/intention of the existing design.
The text was updated successfully, but these errors were encountered: