Skip to content

files.download doesn't properly wait until the operation finishes #809

@wangcheng

Description

@wangcheng

files.download doesn't properly wait until the operation finished. So it is impossible to read the file immediately after downloading it.

After reading the code. I believe it is a bug with the NodeDownloader.download method.

https://github.com/googleapis/js-genai/blob/main/src/node/_node_downloader.ts#L30

There is a PR trying to fix this but it didn't fix all the branches in download function. We also need to properly wait for the pipeline to finish. I drafted a PR to fix this branch.

Environment details

  • Programming language: TypeScript
  • OS: MacOS
  • Language runtime version: Node.js 22
  • Package version: 1.10.0

Steps to reproduce

  1. use files.download download to download a file
  2. read the file immediately using an async API.
  3. notice the file size doesn't reflect the actual file size.
// we are using await here but it doesn't wait until the file is finished being written.
await gemini.files.download({
  file: video, // for example a generated video
  "/tmp/video.mp4",
});

fs.stat(downloadPath, (err, file) => {
  console.log(file.size); // the size is not complete
});

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions