从 Expo App Assets 上传图片到生产服务器

Upload Image from Expo App Assets to Sever in Production

我的 Expo 应用资产中有一张图片,我可以使用以下代码访问它:

const asset = Asset.fromModule(require("...")); 
await asset.downloadAsync();
const localUri = asset.localUri;

现在我想通过获取请求将此图片上传到服务器:

let formData = new FormData();
formData.append('photo', { uri: localUri, name: "photo", type });
fetch("/endpoint", {
      method: 'POST',
      body: formData,
      headers: {'content-type': 'multipart/form-data'}
)

这在使用开发服务器时有效,但在构建 Android.apk.

后失败

两种情况下的localUri(在Android):

Development: file:///data/user/0/host.exp.exponent/cache/ExperienceData/<username>/ExponentAsset-<hexstring>.jpg
Production: asset:///asset_<hexstring>.jpg

好的,我通过 expo-image-manipulator 传递 localUri 然后使用新的 uri 获取命令来解决问题。 图像操纵器将 uri 从 asset:///... 更改为 file:/// uri。

不知道为什么它以前不起作用。