openai / openai/openai-java

File upload fails with `byte[]` or `InputStream` due to requiring filename

Open
#284 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.