0

Here is images coming in request ( from react app)

req.body = {
  imageData: [ 'blob:http://localhost:3000/0bdca87f-47dc-4e56-94ae-ea24e86b6530' ]
}

Now I need to save this on ImageKit ( Node.Js)

imagekit 
    .upload ({
      file : req.body.imageData[0], // not working
     // file : 'convert_blob_to_base64' // not working either
      fileName: 'my_file_name1.jpg'
      
    })
    .then (response => {
      console.log (response);
    })
    .catch (error => {
      console.log (error);
    });

It does save the image but corrupted one, I tried by converting blob to base64, then also it didn't worked out.

if I directly convert the image to base64 using https://www.base64encode.org/ site and use that code as file : 'base_64_directly_encoded_image' then it works

Do I need to store the images first on Node. Js Something, Can Any one guide please.

armin
  • 176
  • 5
  • 16
  • A browser generated blob URL is just that, a URL. It contains no data and is only accessible via the browser that created it. To upload a file, you need to send it as `multipart/form-data` and handle it server-side with something like [Multer](https://github.com/expressjs/multer). Without seeing your client-side code, this isn't really answerable – Phil May 18 '22 at 04:27
  • @Phil Okay let me try that too – armin May 18 '22 at 04:29
  • Does this answer your question? [Node/Express file upload](https://stackoverflow.com/questions/23691194/node-express-file-upload) – Phil May 18 '22 at 04:30

0 Answers0