Search code examples
mobilewin-universal-appstoragefile

Should I remove StorageFile from CameraCaptureUI


I'm creating a univeral app to capture a photo or video and upload it to SharePoint via its REST API. The flow of the current prototype is simple:

  1. On the main page, the user clicks a button to capture a photo or video
  2. A photo or video can be captured using the CameraCaptureUI API
  3. The user is redirected to a page where he/she can enter some metadata
  4. If the user clicks the upload button, the file is sent to SharePoint and the user is sent back to the main page
  5. If the user clicks the cancel button, he/she is sent back to the main page

All of this is working, but I'm not sure what to do with the StorageFile after it's not needed anymore. On the phone, the file is saved to some default location. I'm not copying it to the picture library or whatever, after the file is uploaded (or the user cancelled out) I no longer need it on the device.

Should I take care of deleting this StorageFile myself or does the OS handle this when the app is suspended or closed? I want to avoid that the app is slowly eating more and more storage space over time, for example because the user is closing it before the file is uploaded.

On a side note: I'm not using a background task to upload the file. The user needs to monitor the upload (progress bar) and retry if it fails. If the file cannot be uploaded because there's no internet connection or because SharePoint is down, I no longer care about it.


Solution

  • Everything depends on a place where you have stored the file. If you have used local folder for this, then deleting the file may be a good choice as it won't take memory no more.

    Nevertheless from what I read, your scenario just fits to temporary location. If you use ApplicationData.TemporaryFolder then you don't need to take care of the file as the OS will handle it when needed:

    The temporary app data store works like a cache. Its files do not roam and could be removed at any time. The System Maintenance task can automatically delete data stored at this location at any time. The user can also clear files from the temporary data store using Disk Cleanup. Temporary app data can be used for storing temporary information during an app session. There is no guarantee that this data will persist beyond the end of the app session as the system might reclaim the used space if needed.