0

I have this image

That I would like to convert into a byte array.
I get the file with <v-file-input> and this is the input of it.
I would like to convert it on the client side, then send it to the backend to be uploaded to the sql server.
I've tried to search it on google for hours.

mszabolcs
  • 67
  • 1
  • 10

1 Answers1

1

Try to add this file object to FormData and send it to nodejs. On a server side you can use multer to decode multipart formdata to req.file for instance

on a client side:

  const formData = new FormData()
  formData.append('file', file)

  const { data: result } = await axios.post(`/api/upload-image`, formData)

on a server side:

const multer = require('multer')
const upload = multer()
...
    router.post('/upload-image', upload.single('file'), uploadImageFile)
...
  uploadImageFile(req, res) {
    // multer writes decoded file content to req.file
    const byteContent = req.file
    res.end()
  }
Anatoly
  • 20,799
  • 3
  • 28
  • 42