文件系统 copyAsync 在 iOS 和 Expo 50 中不起作用

问题描述 投票:0回答:1

我使用 Expo 50 在 iOS 中使用 React Native 编写了以下代码。

const uri = photo.uri; // an example of this value is ph://ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED

const uriParts = uri.split(".");
const fileType = uriParts[uriParts.length - 1];
const time = new Date().getTime();

const newUri = `${FileSystem.documentDirectory}/${time}.${fileType}`

await FileSystem.copyAsync({
   from: uri,
   to: newUri,
});

我收到以下错误:

Error: Calling the 'copyAsync' function has failed
→ Caused by: File '' is not readable
Error: Calling the 'copyAsync' function has failed
→ Caused by: File '' is not readable
    at construct (native)
    at apply (native)
    at _construct (http://10.0.0.216:8081/index.bundle//&platform=ios&dev=true&hot=false&transform.engine=hermes&transform.routerRoot=app:10005:28)
    at Wrapper (http://10.0.0.216:8081/index.bundle//&platform=ios&dev=true&hot=false&transform.engine=hermes&transform.routerRoot=app:9963:25)
    at construct (native)
    at _createSuperInternal (http://10.0.0.216:8081/index.bundle//&platform=ios&dev=true&hot=false&transform.engine=hermes&transform.routerRoot=app:133159:322)
    at call (native)
    at CodedError (http://10.0.0.216:8081/index.bundle//&platform=ios&dev=true&hot=false&transform.engine=hermes&transform.routerRoot=app:133172:26)

有类似经历的人吗?

react-native expo expo-file-system
1个回答
0
投票

我认为你在定义

newUri
时犯了一个错误,它应该是
${FileSystem.documentDirectory}${time}.${fileType}
,因为
FileSystem.documentDirectory
已经以尾随
/

结尾
© www.soinside.com 2019 - 2024. All rights reserved.