Maybe anyone know how to send request like this ?
{ 'NewDocuments':[
{
'id':1,
'document': (my image)
}
]}
i need inside Json object send image (not in base64, but as file),
data.files.add(MapEntry(
'document',
MultipartFile.fromBytes(
bytes,
filename: fileName,
contentType: mediaType,
)));
if i send like this is okey, but when it inside "NewDocuments" it is the problem. Maybe you have encountered such problem?
I use Dio package to send request.
3
Answers
Why do you want to send files in JSON? This is not the most suitable format for such data, you should think about other ways to send the document. Perhaps if you describe your needs better, we can give you some advice.
Have you tried this?
Logically, this should work. Try it out
If you want to upload files using a JSON, a multipart request is not the way to go: multiparts exists to upload files, not JSONs.
To actually send your file in a JSON, the better way to do so is to convert your file into a base64 string, essentially sending a stringified version of the document.
As an example, you can do as it follows
and convert each file into base64 string, put them into your JSON and send it in a POST request (I assume).