MediaPicker - Do I have to duplicate the video/image locally?

Javan Joel 1 Reputation point

I'm using the Xamarin.Essentials.MediaPicker to choose images and video to "attach" to notes in my app. I would like these to be referenced locally so they can just open it whenever.

However for iOS, at least, it seems when I open and close the app the reference to the file is lost. Also PickPhotoAsync only has a relative reference to the file, so I cannot even view it using the absolute path because there is no absolute path.

According to this page:

... in the example code they save the image to the local CacheDirectory. I don't want to nor do I see a need to duplicate the file, as that is a waste of resources on the device (especially for video).

For Android this doesn't seem to be an issue. And for UWP it isn't an issue unless I want to play video using the MediaElement (from Xamarin CommunityToolkit).

My question is... do I need to save these files to the local CacheDirectory or is there something I'm missing?

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Javan Joel 1 Reputation point

    @Cole Xia (Shanghai Wicresoft Co,.Ltd.) ... they attach the image to an internal note which can be accessed at any time later. True I can open the stream right away but if I want to open it at a later date it seems I need to save it to the local application folder.

    Also "FullPath" , in iOS, only has a relative value. So the "FullPath" value will be something like "SDS892-SAD343-SDSA.png"

    0 comments No comments

  2. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points

    For image : We can store the stream data as global variable in memory (e.g in App.cs).

    For Video : It seems that we have to store it in local application folder.

    0 comments No comments