首页 > 解决方案 > Android 上的 Expo 和 React Native Axios 文件发布问题 - 无法从 ReadableNativeMap 投射 uri 的值

问题描述

        const uri = await getFileInfo(fileName);
        const body = new FormData();

        body.append('file', {
            uri,
            name: 'helloworld',
            type: 'image/jpeg'
        });

        // process current image
        await axios.post(`${MEDIA_URL}/raw`, body, headers);

上面的代码在 IOS 上运行良好,但在 Android 上我得到以下内容:

java.lang.ClassCastException:uri 的值不能从 ReadableNativeMap 转换为 String

没有明显的迹象表明它来自哪里,但 URI 对象看起来像这样:

Object {
  "exists": true,
  "isDirectory": false,
  "modificationTime": 1560600287,
  "size": 2898352,
  "uri": "file:///data/user/0/com.project.name/files/ExperienceData/%2540project%252Fproject-name/_64_4/838f7807-bb53-4017-bd5a-f8f506292ad3.jpg",
}

有什么迹象表明这是什么原因造成的?

标签: react-nativereact-native-androidexpo

解决方案


推荐阅读