vue-croppa icon indicating copy to clipboard operation
vue-croppa copied to clipboard

Image not passing to backend

Open bjoct16 opened this issue 7 years ago • 5 comments

I could't make it work, It is not passing appropriate data to backend.

this is how my payload looks like when i checked it via network section while submitting the image from front end

Content-Disposition: form-data; name="image"; filename="blob" Content-Type: image/jpeg

And following is the method i am using to upload file.

 const HTTP = axios.create({
    headers: {
      Authorization: 'Bearer <token>'
    }
  })

  this.myCroppa.generateBlob((blob) => { 
    var fd = new FormData()
    fd.append('image', blob)
    
    HTTP.post(`http://localhost:8000/upload`, fd)
    .then(function (res) {
      console.log(res.data)
    })
    .catch(function (err) {
      console.log(err.response.data)
    })
  }, 'image/jpeg', 0.8)

Note: My backend controller is working perfectly , Postman and other methods are working smoothly.

bjoct16 avatar Feb 06 '18 05:02 bjoct16

What is the backend upload API like? Does it support multipart/form-data as content-type?

zhanziyang avatar Feb 06 '18 08:02 zhanziyang

sorry for the late reply , i was away for weeks , well yes , multipart/form-data is working as usual. I am using yii2 as a backend server.

bjoct16 avatar Feb 22 '18 11:02 bjoct16

Did anyone manage to solve this. I'm experiencing the same issue here. I tried tacking the base64 string and converting it manually to a file using the Javascript File constructor without results.

juansaab avatar Mar 19 '18 22:03 juansaab

try to do it with Formidable

image

image

image

  form.on('file', function(name, file) 
        {                
            util.PrintI("form.on('file'):") 
            util.PrintI(name) 
            util.PrintI(file)
         }

In my code: this.rowItem.selectedFile = the blob Use promises or async/await

This works for me: https://github.com/felixge/node-formidable

mutter also worked for me https://github.com/expressjs/multer

davidramos-om avatar Jun 06 '18 07:06 davidramos-om

Old issue but I think it's still relevant, this won't work:

 fd.append('image', blob)

Even without using Formidable, if you add a third argument it will/should work.

 fd.append('image', blob, 'same_name.png')

ref. https://github.com/zhanziyang/vue-croppa/issues/129

paolodina avatar Sep 24 '20 14:09 paolodina