How to download and store an image using Windows.Web.Http? RRS feed

  • Question

  • How do I download and store a jpeg image from the internet in a Windows Store App with Windows.Web.Http?

    The problem that I am facing is that I don't know what Get…Async and Write…Async method I must use for an image? It is very different with files, than with strings.

    Please, only Windows.Web.Http!

    Please, no third-party solutions!

    If you suggest something else, please use the comment section, not the answer. Thank you!

    using Windows.Storage;
    using Windows.Web.Http;

    Uri uri = new Uri("http://image.tmdb.org/t/p/w300/" + posterPath); HttpClient httpClient = new HttpClient(); // I guess I need to use one of the Get...Async methods? var image = await httpClient.Get…Async(uri); StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFolder cachedPostersFolder = await localFolder.CreateFolderAsync("cached posters", CreationCollisionOption.OpenIfExists); StorageFile posterFile = await cachedPostersFolder.CreateFileAsync(posterPath, CreationCollisionOption.ReplaceExisting); // I guess I need to use one of the Write...Async methods? await FileIO.Write…Async(posterFile, image);

    Sunday, November 2, 2014 10:24 PM