FileReader 无法从相机读取文件 - Xamarin + WebView
FileReader is not able to read a file from camera - Xamarin + WebView
我有一个应用程序,它只是一个 VUE PWA 的容器。在一个页面中,用户可以上传一些文件。我实施了以下解决方案,让用户可以选择 select 来自 Galery 的文件或拍摄新照片。
https://blog.verslu.is/xamarin/xamarin-forms-xamarin/building-a-hybrid-app-with-xamarin-forms/
问题是当用户用相机拍摄新照片时,FileReader 无法读取文件。如果用户 select 有一个现有文件,则上传效果很好。这是错误:
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"
我注意到一个区别:当用户select从图库中下载文件时,APP 发送到 WebView 的 URI 路径如下所示:
{content://com.android.providers.media.documents/document/image%3A32681}
当用户拍摄新照片时:
file:///storage/emulated/0/Pictures/JBSTRIP/IMG_637273232207442660.jpg
有人遇到过同样的问题吗?我没有从网上找到任何解决方案。
非常感谢!
我解决了这个问题。
我更改了相机图片的保存目录:
改为使用以下方式获取路径:
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");
我有一个应用程序,它只是一个 VUE PWA 的容器。在一个页面中,用户可以上传一些文件。我实施了以下解决方案,让用户可以选择 select 来自 Galery 的文件或拍摄新照片。
https://blog.verslu.is/xamarin/xamarin-forms-xamarin/building-a-hybrid-app-with-xamarin-forms/
问题是当用户用相机拍摄新照片时,FileReader 无法读取文件。如果用户 select 有一个现有文件,则上传效果很好。这是错误:
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"
我注意到一个区别:当用户select从图库中下载文件时,APP 发送到 WebView 的 URI 路径如下所示:
{content://com.android.providers.media.documents/document/image%3A32681}
当用户拍摄新照片时:
file:///storage/emulated/0/Pictures/JBSTRIP/IMG_637273232207442660.jpg
有人遇到过同样的问题吗?我没有从网上找到任何解决方案。
非常感谢!
我解决了这个问题。 我更改了相机图片的保存目录:
改为使用以下方式获取路径:
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");