Skip to main content

Getting "API upload did not contain a file part" while using box-typescript-sdk-gen

  • April 2, 2024
  • 5 replies
  • 325 views

Here is my code:

  public uploadFiles = async (folderName: string, files: Blob[]) => {

    const folderId: string = await this.getFolderId(folderName);

    for (const file of files) {

      const stream: Readable = await blobToReadable(file);

      const attributes: UploadFileRequestBodyAttributesField = {
        name: file.name,
        parent: { id: folderId }
      }

      await this.boxClient.uploads.uploadFile({ attributes, file: stream });

    }

  }
const blobToReadable = async (blob: Blob): Promise<Readable> => {
  
  const buffer: Buffer = Buffer.from(await blob.arrayBuffer());
  const stream = Readable.from(buffer);

  return stream;

}

I am using Bun.js instead of node. folderId is correct and the file is converted correctly from Blob to Readable

5 replies

  • Box Employee
  • 21 replies
  • April 3, 2024

Hi @user220,

It seems that Bun.js is having trouble handling FormData correctly in the form we use in our SDK (we use the form-data library).
Additionally, there are many open issues related to FormData in the Bun.js repository here, indicating an existing problem in this area.

Unfortunately, we are unable to provide a quick fix as we did not intend to support Bun in the long term.
However, we will discuss adding support for Bun within our team.

For now, I can only recommend using Node.js, where our library works correctly.


  • Author
  • New Participant
  • 1 reply
  • April 3, 2024

So is it possible to upload a file using the API.


rbarbosa Box
Forum|alt.badge.img
  • Developer Advocate
  • 556 replies
  • April 3, 2024

Hi @user220 ,

Yes it is, here are a few examples:

curl --location 'https://upload.box.com/api/2.0/files/content?fields=id%2Ctype%2Cname' \
--header 'Content-Type: multipart/form-data' \
--header 'Authorization: Bearer W...V' \
--form 'attributes="{
  "name": "working-with-box-sign.png",
  "parent": {
    "id": "234108232105"
  }
}"' \
--form 'file=@"/Users/rbarbosa/Downloads/working-with-box-sign.png"'

Let us know id this helps

Best regards


  • Participating Frequently
  • 5 replies
  • April 23, 2024

The rest API is not working. Showing the “API upload did not contain a file part” error


rbarbosa Box
Forum|alt.badge.img
  • Developer Advocate
  • 556 replies
  • April 23, 2024

Please create a new post and elaborate on your situation.

The “API isn’t working” does not help us identify the issue.