相关疑难解决方法(0)

enctype ='multipart/form-data'是什么意思?

enctype='multipart/form-data'HTML表单中的含义是什么?我们何时应该使用它?

html multipartform-data http-headers

1290
推荐指数
7
解决办法
95万
查看次数

向 API 请求 formData,上传图片时 axios 出现“网络错误”

我正在向服务器发出 POST 请求以上传图像并在 react-native 中使用 axios 发送表单数据。我收到“网络错误”。我也尝试 fetch 但没有任何效果。使用 react native image picker libeary 选择 image.in postman api 工作正常

        formData.append('title', Title);
        formData.append('class_id', selectClass._id)
        formData.append('subject_id', checkSelected)
        formData.append('teacher_id', userId)
        formData.append('description', lecture);
        formData.append('type', 'image');

       var arr=[];
       arr.push(imageSource)
       arr.map((file,index)=>{
       formData.append('file',{
       uri:file.path,
       type:file.type,
       name:file.name
       })
       })


       axios({
       method: 'post',
       url: URL + 'admin/assignment/create',
       data: data,
       headers: {
       "content-type": "multipart/form-data",
       'x-auth-token': token,
        },
       })
     .then(function (response) {
    //handle success
    console.log('axios assigment post',response);
      })
   .catch(function (response) {
     //handle error
      console.log('axios assigment post',response);
    });
Run Code Online (Sandbox Code Playgroud)

multipartform-data react-native axios react-native-android react-native-image-picker

10
推荐指数
6
解决办法
7905
查看次数