expo downloadasync don' t下载文件,其中包含文件名中的空格
在尝试从Firebase存储下载文件时,我对下载ASYNC
有问题。如果文件名不包含空格,则可以正常运行,并且将文件下载到应用程序中,但是如果它具有文件名中的空间,则该文件将被忽略并且未下载。问题仅在iOS中出现,而对于Android,我没有这个问题。
firebase也为我提供了该文件的链接,因此Firebase没有问题。
这就是我的代码的外观:
await getDownloadURL(
ref(
storage,
`/images/objects/${touristObject.id}/${file}`
)
)
.then(async (url) => {
const fileReference =
`${FileSystem.documentDirectory}images/objects/${touristObject.id}`
await FileSystem.makeDirectoryAsync(
fileReference,
{ intermediates: true }
)
await FileSystem.downloadAsync(
url,
`${fileReference}/${file}`
)
.then((uri) => { resolve() })
.catch((error) => {
console.warn(error)
resolve()
})
})
.catch((error) => {
console.warn(error)
resolve()
})
I have a problem with DownloadAsync
when trying to download files from Firebase storage. If filename doesn't contain spaces it works fine and file is downloaded to app, but if it have a space in file name, then that file is ignored and not downloaded. Problem appears only in iOS, with Android I did't have this problem.
Also Firebase gives me a link for that file, so there is no problem with Firebase.
This is how my code looks:
await getDownloadURL(
ref(
storage,
`/images/objects/${touristObject.id}/${file}`
)
)
.then(async (url) => {
const fileReference =
`${FileSystem.documentDirectory}images/objects/${touristObject.id}`
await FileSystem.makeDirectoryAsync(
fileReference,
{ intermediates: true }
)
await FileSystem.downloadAsync(
url,
`${fileReference}/${file}`
)
.then((uri) => { resolve() })
.catch((error) => {
console.warn(error)
resolve()
})
})
.catch((error) => {
console.warn(error)
resolve()
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要
注意,不编码
filesystem.documentDirectory
本身,因为它已经编码。仅在其之后编码您附加的路径或文件名。You may need to encode the file name:
Note that do not encode
FileSystem.documentDirectory
itself because it is already encoded. Only encode the path or filename you append after it.