-1

can i send file inside a json through ajax:

colors: [
{_id: "5bec42f02797800f447241d1", color: "#777", image: File(79666)},
{_id: "5bec8cf91fb21b3a2477d817", color: "#566", image: File(79666)}
]

If not how to send this data through ajax.

code:

formData.append('colors', JSON.stringify(data)); 

i am getting data.colors[0].image as {} while sending

Varun Gopal K.P
  • 265
  • 4
  • 14

1 Answers1

0

you can convert your file to Base64 string and send it through JSON.

On receiving, convert this Base64 string back to desired file format

This may help on how to convert file to base64: How to convert file to base64 in JavaScript?

Manish Gharat
  • 400
  • 1
  • 10