我的代码:

const file = {
  uri: this.state.imageSource,
  name: this.state.imageName,
  type: 'image/jpg',
};

const data = new FormData();
data.append('file', file);

fetch(config.server + '/upload', {
  method: 'POST',
  body: data,
})
  .then((res) => res.json())
  .then((responseData) => {
    alert(JSON.stringify(responseData));
  })
  .catch((err) => {
    alert(err);
  });

如果没有FormData码,则不会显示错误.我该怎么做才能修复?在android上调试.

推荐答案

错误是因为我以数组的形式传入url,但它需要一个字符串.

React-native相关问答推荐

原生react :顶部的滑块位置

领带麦克风在Reaction-Native-Incall-Manager中不工作

1.5.1 nxworkspace+react-native 版本的Axios url未定义问题

React-native 重置数据库

React Native - Expo:fontFamily 'SimpleLineIcons' 不是系统字体,尚未通过 Font.loadAsync 加载

PanResponder 在第二次拖动时将 Animated.View 捕捉回原始位置

withNavigation 只能用于导航器的视图层次 struct

在 React Native 中计算两个 lat+lng 坐标之间的距离?

在 react-native 元素中更改 android 和 ios 的入口文件路径

用于 React-Native 开发的 Visual Studio Code 中的自动导入

如何解决react-navigation 问题:Animated: `useNativeDriver` is not supported because the native animated module is missing.?

我可以在 react-native 中使用 reactJS 库吗?

xcode 8.3 框架未找到架构 armv7 的 FileProvider

当组件在react-native 中重新呈现时,动态不透明度不会改变

props验证中缺少 React Navigation 'navigation'

require() 必须有一个字符串文字参数 React Native

有react-native复选框的例子吗?

无法解析模块react-navigation

试图在一个本应是不可变且已被冻结的对象上设置密钥

React Native:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败