expo downloadasync don' t下载文件,其中包含文件名中的空格

发布于 2025-02-10 04:06:28 字数 860 浏览 0 评论 0原文

在尝试从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒与心事 2025-02-17 04:06:28

您可能需要

encodeURI(fileName)

注意,不编码filesystem.documentDirectory本身,因为它已经编码。仅在其之后编码您附加的路径或文件名。

You may need to encode the file name:

encodeURI(fileName)

Note that do not encode FileSystem.documentDirectory itself because it is already encoded. Only encode the path or filename you append after it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文