Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我想通过Fetch/Axios中的formData发送包含图像的字典对象数组_Javascript_Json_Reactjs_Axios_Fetch - Fatal编程技术网

Javascript 我想通过Fetch/Axios中的formData发送包含图像的字典对象数组

Javascript 我想通过Fetch/Axios中的formData发送包含图像的字典对象数组,javascript,json,reactjs,axios,fetch,Javascript,Json,Reactjs,Axios,Fetch,嘿,我想用fetch发送这些数据,有人能告诉我怎么做吗 { "User": "irjhiosd@#Dsadm", "name": "Some Name Here" pictures : [ { picture : @PICTURE_FILE_HERE }, { picture : @PICTURE_FILE_HERE }, { picture : @P

嘿,我想用fetch发送这些数据,有人能告诉我怎么做吗

{
    "User": "irjhiosd@#Dsadm",
    "name": "Some Name Here"
    pictures : [
       { picture : @PICTURE_FILE_HERE },
       { picture : @PICTURE_FILE_HERE },
       { picture : @PICTURE_FILE_HERE }
    ]
}

这在很大程度上取决于服务器对数据的期望structured@Quentin确切地如果它是多部分的,请参阅服务器希望以Django标准的格式数据发送文件API@p32094问题是通常你可以用键和值来附加表单数据,我的用例值是一个包含json对象的数组,其中包含我不确定如何处理的文件
const toBase64 = file => new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => resolve(reader.result);
    reader.onerror = error => reject(error);
});

let imageArray = []
// SAY U HAVE PICTURES IN A 'pictures' ARRAY
pictures.forEach((picture)=>{
    imageArray.push(  {'picture' : picture})
})
fields['pictures'] = imageArray

// After this u can normally send feilds as body in your fetch / axios request