File upload fails with `byte[]` or `InputStream` due to requiring filename
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 1.5k
- Forks
- 264
- Avg merge
- 9h 46m
- Merged PRs (30d)
- 96
Description
I am trying to upload a file using the OpenAI Java SDK and encountered an issue where the request fails when using InputStream, but succeeds when using Paths.get().
Use Code
public String uploadFile(MultipartFile file) {
FileCreateParams params = FileCreateParams.builder()
.file(file.getInputStream()) // Using InputStream
.purpose(FilePurpose.ASSISTANTS)
.build();
FileObject fileObject = openAIClient.files().create(params);
return fileObject.id();
}
When using InputStream, the following error occurs:
400: OpenAIError{additionalProperties={error={message=The browser (or proxy) sent a request that this server could not understand., type=server_error, param=null, code=null}}}
However, when I use Paths.get() instead, the request succeeds without issues.
Is this an expected behavior, or am I incorrectly using the SDK?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the upload through FileCreateParams.file(InputStream) and compare it with the successful Paths.get() path in files().create. Trace how each input is represented in the multipart request, especially filename handling. Done means byte[] and InputStream uploads work without the reported 400 error while path-based uploads continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100