Closed neetrath closed 8 years ago
Yes, have faced this. Further, this temp file is only available for a short time. I was trying to upload the image after using PickPhotoAsync but the temp file was getting deleted very soon. Ultimately, I ended up copying the file first to the app's folder and then uploading it.
This also means that we have to copy the local file and keep extra copy for our own app, while there is no need if we get the actual path of the file. It just wastes precious device storage memory. Same is true for PickVideo also.
Hmmm intriguing, yes it should keep it in private storage and give you access to it.... I will look into this.
I don't think that it should be stored in private storage. Here is the scenario I want to accomplish:
Say I have images/videos in the Gallery or other such apps. Usually, it is stored in the public external storage in Android(no idea about ios & windows) which is accessible by all apps. Hence, the Pick Api should just return the original absolute path. That way, I can choose to just keep the file path stored in my app instead of copying(duplicating) the whole file and always display from there. If the pick photo api is providing access to private files of other apps, then your current approach of copying the file to a temporary file in the Public folder: sdcard/0/Android/data//files/Picture/temp/ and providing access to it and deleting the file on disposal of file reference is fine.
So the API should return 2 things: 1) File Path: original absolute path if it is not a temporary file. 2) bool IsTemporary.
We are facing same issue. Still returning temp path.
var file = await CrossMedia.Current.PickPhotoAsync(); Image.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); file.Dispose(); return stream; });
await CrossMedia.Current.PickPhotoAsync ().ContinueWith(t => { if (t.IsCompleted) { MediaFile file = t.Result; stream = t.Result.GetStream();
}
}, TaskScheduler.FromCurrentSynchronizationContext());;
Image.Source = ImageSource.FromStream(() => stream);
Tested for both ios and Android.
Is this code in my sample app?
My code disposes of the photo as it is just a sample that is why the file is all cleaned up is my assumption.
Yes, Actual code given above is as part of Usage section of https://components.xamarin.com/gettingstarted/mediaplugin.
When we try to utilize PickPhotoAsync method and try to access MediaFile result of PickPhotoAsync having access issues in Android (Temp file).
My fix sample suggest instead of using MediaFile which has restricted access, we can use result of PickPhotoAsync (t.Result) to get rid of Accessiblity issue.
If we can able to get actual image path instead of temp path, that option will be more helpful. In above comment, i got rid of temp file accessibilty issue to show Image source.
Ah, I can change the sample :)
I got a bug with the PickPhotoAsync. At the first installation of the app, the PickPhotoAsync do not import the picture. I do some test on others devices (Galaxy S3, Galaxy Note2 and Galaxy Note4) and the bug is only present on Nexus 5 LG. Can you confirm if someone his having this bug.
You can use some of the cloud test services and test it there. Testdroid has an interactive test option, in which you upload your app and then do interactive manual testing. These testclouds have many devices available and you can chose the specific device you want to test. Besides TestDroid, many other such cloud test providers also provide both- manual and automated testing option.
@iitr-ankur This is a good idea ! But for right now I can't really use this. I'm convinced that the problem come from something inside MediaPicker because I use the test project here : https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/Media/MediaAndroidTest
and the PickPhoto and PickVideo doesn't work on LG Nexus 5 (5.1.1) and maybe all other device with (5.1.1) will not work too. I'm trying to resolve it.
I fixed issue in latest alpha with 5.1.1 devices.
@jamesmontemagno It works ! Thank you
Glad to hear :) I have tested it on 4.4 and 5.1.1. I have actually closed a different issue for the 5.1.1 device.
I need to validate the original issue here in 47, which is deletion of photo, however it seems to work.
This is no longer an issue. Closing out.
Same issue still occurs on iOS though.
This is still an issue on IOS
CrossMedia.Current.PickPhotoAsync() on android not return real file path. It returns path in sdcard/0/Android/data//files/Picture/temp/ / it throws the System.IO.FileNotFoundException because real file is at sdcard/0/DCIM/Camera.