Skip to main content

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

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.


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


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


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


Please create a new post and elaborate on your situation.



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


Reply