FileReader无法从摄像头读取文件 - Xamarin + WebView

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

我有一个APP,只是一个VUE PWA的容器。在一个页面中,用户可以上传一些文件。我实现了以下解决方案,让用户可以选择从Galery中选择一个文件或拍摄一张新照片。

https:/blog.verslu.isxamarinxamarin-forms-xamarinbuilding-a-hybrid-app-with-xamarin-forms。

问题是当用户用相机拍摄新的照片时,FileReader无法读取文件,如果用户选择了一个已有的文件,上传就能顺利进行。这就是错误。

FileReader: 
message: "The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired."
name: "NotReadableError"

我注意到一个不同的地方:当用户从galery中选择一个文件时,APP发送给WebView的URI路径看起来是这样的。

{content://com.android.providers.media.documents/document/image%3A32681}

当用户拍摄一张新照片时。

file:///storage/emulated/0/Pictures/JBSTRIP/IMG_637273232207442660.jpg

有人遇到过同样的问题吗?我没有从网上找到任何解决方案。

非常感谢!

android vue.js xamarin.forms filereader
1个回答
1
投票

我解决了这个问题.我改变了图片从相机保存的目录。

而不是使用路径。

File imageStorageDir = new File (Android.OS.Environment.GetExternalStoragePublicDirectory (
                    Android.OS.Environment.DirectoryPictures), "APP");

我使用APP的文件夹。

 File imageStorageDir = new File (_context.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures), "APP");
© www.soinside.com 2019 - 2024. All rights reserved.