#file upload blob fail

1 messages · Page 1 of 1 (latest)

humble minnow
#

can u send the whole script, I wanna poke around see if I can help

humble minnow
#

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

chilly dove
#

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

azure swan
#

just use Bun.write('path-to-file.extension', fileBlob)

#

Bun automatically overwrites the existing file

chilly dove
#

it doesnt work

azure swan
#

really weird behaviour, tried uploading png as well and my code definitely works

chilly dove
#

maybe its because of wsl?

azure swan
azure swan
chilly dove
#

have you put some headers?

azure swan
#

no need to put headers when using formdata, the browser does it for us

#

definitely issue with bun