bun
bun copied to clipboard
fetch request form-data
What version of Bun is running?
1.1.20
What platform is your computer?
No response
What steps can reproduce the bug?
export async function upload(fileBit: Buffer, fileName?: string): Promise<Response> {
const fileType = await fileTypeFromBuffer(fileBit);
if (!fileType) throw new Error("读取文件类型失败");
const formData = new FormData()
formData.append("file", new Blob([fileBit]), fileName || `${Date.now()}.${fileType.ext}`)
return await postRequest(`${Bun.env.gateway}/${Bun.env.fs || "fs"}/attachments/upload`, formData)
}
let body = `
{
"idcard_number": "",
"default_floor": 0,
"temperature_type": 0,
"person_code": "",
"person_name": "EYE",
"pass_type": 1,
"photo": "bse64",
}
`
const map = JSON.parse(body)
// console.log(`${btoa(atob(map["photo"]))==map["photo"]}`)
const res = await upload(Buffer.from(map['photo'],'base64'))
Server reception POST "/attachments/upload" 2024-07-18 15:25:07.247 INFO 1 --- [nio-8080-exec-5] c.b.f.c.log.webmvc.LoggingFilter : [1721287507263][处理中]请求函数 = com.becypress.product.file.attachment.AttachmentController.upload 2024-07-18 15:25:07.248 INFO 1 --- [nio-8080-exec-5] c.b.f.c.log.webmvc.LoggingFilter : [1721287507263][处理中]请求参数 = [null, null, ---WebkitFormBoundaryb2e40a8664294357a0aa67ee10ab6685 Content-Disposition: form-data; name="file"; filename="7219603076083098624.jpg" Content-Type: application/octet-stream
expect Content-type multipart/form-data
What is the expected behavior?
No response
What do you see instead?
No response
Additional information
No response