Bienvenue à Blogs CodeS-SourceS Identification | Inscription | Aide

[wpdev] Storage bug in MediaLibrary.SavePicture

I’ve received many reports lately of users complaining of abnormal storage usage from one of my apps, Imageboard Browser.The application was in some cases storing hundreds of megabytes! I thought at first that it was just the "other storage” issue, but I did some further investigation just in case.

After some trial and error and a bit of luck, I’ve discovered that the bug lies in the methods MediaLibrary.SavePicture and MediaLibrary.SavePictureToCameraRoll. As their name indicate, they are used to save a picture to the phone’s picture hub, and they do their job pretty well. Except that ever time you use them, a copy of your picture is stored in the isolated storage!

To confirm this, I’ve written a small application with two buttons. It’s as simple as it can get: the “download” button downloads a picture, and saves it to the picture hub. The “storage” button displays the contents of the isolated storage:

   1: private void ButtonDownload_Click(object sender, RoutedEventArgs e)
   2: {
   3:     var webClient = new WebClient();
   4:  
   5:     webClient.OpenReadCompleted += WebClient_OpenReadCompleted;
   6:  
   7:     webClient.OpenReadAsync(new Uri("http://i.s-microsoft.com/global/ImageStore/PublishingImages/FY13/Asset/highlights/WPbuy_BG_0225_420x210_FR_FR.jpg"));
   8: }
   9:  
  10: private void WebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
  11: {
  12:     using (var mediaLibrary = new MediaLibrary())
  13:     {
  14:         mediaLibrary.SavePicture("1", e.Result);
  15:     }
  16:  
  17:     MessageBox.Show("Done");
  18: }
  19:  
  20: private void ButtonStorage_Click(object sender, RoutedEventArgs e)
  21: {
  22:     using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
  23:     {
  24:         var files = isolatedStorage.GetFileNames();
  25:  
  26:         MessageBox.Show(string.Join("\r\n", files));
  27:     }
  28: }

When running the application for the first time, the “storage” button shows that the isolated storage is empty:

cap1

 

Then, after using the “download” button to download a picture and save it to the picture hub, the “storage” button finds one file!

cap2

 

Since there’s no built-in tool in Windows Phone to explore the isolated storage, it’s a bug that can be easily overlooked.

I’ve been doing a few more tests about this bug, and here are my findings so far:

- I could not reproduce the bug on Windows Phone 7, only Windows Phone 8 seems affected.

- I could reproduce the issue on various devices (Lumia 822, Lumia 920, and the emulator). So it’s unlikely that the bug is hardware-specific.

- The bug occurs only when saving JPG pictures. Nothing is stored on the isolated storage when saving a PNG picture.

- If I anticipate and create beforehand a file on the isolated storage with the same name, it will be overwritten. If I lock it by keeping the stream open, the MediaLibrary.SavePicture method throws an exception.

- The MediaLibrary.SavePicture has an overload that expect a byte array rather than a stream. It suffers from the same bug.

- The name of the file created in the isolated storage is the same name as the one provided to the MediaLibrary.SavePicture, with “.jpg” appended to the end (even if the name already contained “.jpg”), and dots ‘.’ replaced by underscores ‘_’. Knowing this, it’s possible to write code to automatically delete the file.

- On Nokia’s storage tool, those files are reported in the application’s dedicated storage. Not in the temp files or the “others” storage.

In a nutshell, if you’re saving pictures to the picture hub, make sure you’re deleting the temporary files in the isolated storage afterwards. I hope Microsoft will be able to provide a fix quickly, as it can quickly become an issue on devices with low storage.

Also, I only have been able to test on the latest version of the WP8 OS (8.0.10211.204). If you still have a device with an older version of the OS, could you please try to reproduce the bug on it? I’m eager to know if the bug was introduced on the latest version of WP8 or if it has always been standing there.

Publié dimanche 26 mai 2013 19:08 par KooKiz
Ce post vous a plu ? Ajoutez le dans vos favoris pour ne pas perdre de temps à le retrouver le jour où vous en aurez besoin :

Commentaires

Pas de commentaires
Les commentaires anonymes sont désactivés

Les 10 derniers blogs postés

- Focus Sauvegardes SharePoint par Le blog de Patrick [MVP SharePoint] le il y a 3 heures et 5 minutes

- Technofolies, votre évènement numérique de l'année par Le Blog (Vert) d'Arnaud JUND le 09-26-2014, 18:40

- Xamarin : From Zero to Hero par Fathi Bellahcene le 09-24-2014, 17:35

- Conférences d’Automne 2014 par Le blog de Patrick [MVP SharePoint] le 09-24-2014, 14:53

- [TFS] Supprimer un projet de Visual Studio Online par Blog de Jérémy Jeanson le 09-22-2014, 20:42

- Nouveau blog en anglais / New blog in english ! par Le blog de Patrick [MVP SharePoint] le 09-18-2014, 18:42

- [ #Yammer ] From Mailbox to Yammer and back / De votre messagerie vers Yammer et retour ! par Le blog de Patrick [MVP SharePoint] le 09-15-2014, 11:31

- [ #Office 365 ] New service settings panel / Nouveau panneau de paramétrage des services par Le blog de Patrick [MVP SharePoint] le 09-11-2014, 08:50

- Problème de déploiement pour une démo SharePoint/TFS? par Blog de Jérémy Jeanson le 09-10-2014, 21:52

- [ #Office365 ] Delve first impressions / Premières impressions sur Delve par Le blog de Patrick [MVP SharePoint] le 09-09-2014, 16:57