I was using axios to send form-data in RN but it's not working. Noww tried fetch every feild uploads except images. If i use postman, everything works fine.enter image description here

这是我的代码:

const postOrder = () => {
    var data = new FormData();
    data.append('marca', marca);
    data.append('modeo', modeo);
    data.append('option', option);
    data.append('descripcion', descripcion);
    data.append('images[]', images);
    data.append('userId', '2');
    dispatch(saveOrder(data));
  };
    fetch(`${baseUrl}/save-order`, {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'multipart/form-data',
    },
    body: data,
  })
    .then(res => res.json())
    .then(json => {
      // dispatch({type: 'ORDER', payload: response.data});
      console.log('json1', json);
    })
    .catch(error => {
      console.log(error);
    });

除图片外,所有房产/场地均已上传.我也try 过这些方法

data.append('file', {
      uri: images,
      type: 'image/jpeg',
      name: 'images[]',
    });
data.append('file',images,'images[])

推荐答案

const formData = new FormData();
    formData.append('file', {
      uri: pictureUri,
      type: 'image/jpeg',
      name: 'profile-picture'
})

我也有同样的问题,在formData的文件属性中添加了类型:"image/jpeg",修复了这个问题.

Javascript相关问答推荐

我应该如何在此Angular 16应用程序中的方法中使用@ Hostspel?

promise .all()永不解决

如何用变量productId替换 1"

IOS(React Native)中未找到模块SquareReaderSDK

如何在不指定宽度和高度的情况下显示来自网址的下一张图像

在卡信息之间切换

如何使用Paged.js仅渲染特定页面

我可以使用CSS有效地实现最大宽度=100%和最大高度=100%,而无需父母有明确的/固定的宽度和高度,替代方法吗?

判断表格单元格中是否存在文本框

WebRTC关闭navigator. getUserMedia正确

在grafana情节,避免冲突的情节和传说

从Node JS将对象数组中的数据插入Postgres表

当Redux提供程序访问Reduxstore 时,可以安全地从Redux提供程序外部调用钩子?

如何使用子字符串在数组中搜索重复项

IF语句的计算结果与实际情况相反

Angular 形式,从DOM中删除不会删除指定索引处的内容,但会删除最后一项

自定义图表工具提示以仅显示Y值

未捕获的运行时错误:调度程序为空

处理TypeScrip Vue组件未初始化的react 对象

使用可配置项目创建网格