Skip to content
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

Allow readable streams to be uploaded #524

Closed

Conversation

tarcisiozf
Copy link

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Right now there is no way to upload files using a read stream unless it's coming from a fs.ReadStream. This forces the user to go through disk first before sending a stream or to reallocate the whole content to send as Buffer.

In my use case I'm handling a audio stream via web API, transforming the webm via stream and, unfortunately, persisting the file before sending.

The fs.ReadStream already extends a stream.Readable so we can do a small extension to the code without needing to change behavior.

For this PR I decided to add support for Readable instead of replacing the existing FsReadStream checks. I also know that the code is unlikely to be merged but it demonstrates a simple solution to it.

@rattrayalex
Copy link
Collaborator

I don't believe this would work well with the current OpenAI API, which inspects filenames for media types (eg, you need a .mp3 extension for an audio file to be interpreted as mp3). That's why we only allow fs.createReadStream() to bypass toFile() – it includes a filename.

This may work with node Readable, but would it work with web ReadableStream?

Does this actually make the request as expected with a large file, streaming the request body? I think further changes would be required for that, and we might be best off waiting for #402 to land for that.

@tarcisiozf
Copy link
Author

Thanks for the reply, now the API constraints are clear to me. For now I'll use await toFile(buffer, 'audio.webm') instead of a stream solution.

@tarcisiozf tarcisiozf closed this Nov 22, 2023
@tarcisiozf tarcisiozf deleted the feature/upload-readable-stream branch November 22, 2023 12:26
@rattrayalex
Copy link
Collaborator

Great. You may want to follow #418 which documents a feature request for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants