jamesmontemagno / Xamarin.Plugins

Cross-platform Native API Access from Shared Code!
MIT License
1.3k stars 380 forks source link

PickPhotoAsync Problem #47

Closed neetrath closed 8 years ago

neetrath commented 9 years ago

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.

iitr-ankur commented 9 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.

iitr-ankur commented 9 years ago

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.

jamesmontemagno commented 9 years ago

Hmmm intriguing, yes it should keep it in private storage and give you access to it.... I will look into this.

iitr-ankur commented 9 years ago

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.

ramu-sriramoju commented 9 years ago

We are facing same issue. Still returning temp path.

ramu-sriramoju commented 9 years ago

Actual code:

var file = await CrossMedia.Current.PickPhotoAsync(); Image.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); file.Dispose(); return stream; });

Fix:

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.

jamesmontemagno commented 9 years ago

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.

ramu-sriramoju commented 9 years ago

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.

ramu-sriramoju commented 9 years ago

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.

jamesmontemagno commented 9 years ago

Ah, I can change the sample :)

davidlebr1 commented 9 years ago

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.

iitr-ankur commented 9 years ago

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.

davidlebr1 commented 9 years ago

@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.

jamesmontemagno commented 9 years ago

I fixed issue in latest alpha with 5.1.1 devices.

davidlebr1 commented 9 years ago

@jamesmontemagno It works ! Thank you

jamesmontemagno commented 9 years ago

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.

jamesmontemagno commented 8 years ago

This is no longer an issue. Closing out.

aiartsev commented 8 years ago

Same issue still occurs on iOS though.

NVentimiglia commented 7 years ago

This is still an issue on IOS