#file upload blob fail
1 messages · Page 1 of 1 (latest)
In the part where you are reading/writing the file, you aren't setting a dest, unless the dest is the PNG Bunfile. Maybe you meant to flip them, or are you trying to read the data that's in the PNG file and make that the file dest? If so, I'd want to use something like this
const fileInfo = Bun.read("xyz")
const fileDest = fileInfo.text() // You could also just do this in the first arg of the write, you don't have to make it a variable
// Maybe pass it to the Bun path module to get the full path
Bun.write(fileDest, file)
but I don't know, Also why does your IDE underline the profile()[0]? Maybe its possible that you need to await the profile function that you are calling??
If you could give more info about what you are trying to do that would be helpful
backend
.post('/uploadpro', ({ body:{file} }) => {
Bun.write(Bun.file('./public/account/22.png'), file)
return file
}, {
body: t.Object({
file: t.File()
})
})
frontend
const imgupdate = (e) =>{
e.preventDefault()
const formdata1 = new FormData()
// formdata1.append('id',params.id)
formdata1.append('file',profile()[0])
//in react this is a usestate like const [profile, setprofile] = useState(""); im using solidjs
//it hold the value of image
fetch(
`http://localhost:4000/uploadpro`,{
method: 'POST',
body: formdata1
}).then(()=>{
setimgset('http://localhost:4000/public/account/'+params.id+'.png')
// location.reload();
})
}
Bun.file('./public/account/22.png') replace or create i want to place the value of file here.
it worked on txt file but on image it doesnt
just use Bun.write('path-to-file.extension', fileBlob)
Bun automatically overwrites the existing file
maybe its because of wsl?
likely because of that, Bun is still experimental in windows
have you put some headers?
no need to put headers when using formdata, the browser does it for us
also this is a known issue:
https://github.com/oven-sh/bun/issues/4879
definitely issue with bun