How to DownLoad Network Image And Save Image to mobile storage
by using WebClient in Android and Ios using Dependencies
write a button click event
and also create a dependency service
using System.Net; using System.IO; using System.Text; [assembly : Dependency(typeof(ShortcutGenerateService))] namespace Downloadfile.Droid { public class DownloadService : IDownloadService { public async void DownloadImage() { var webClient = new WebClient(); webClient.DownloadDataCompleted += (s, e) => { var bytes = e.Result; // get the downloaded data string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); string localFilename = "downloaded.png"; string localPath = Path.Combine (documentsPath, localFilename); File.WriteAllBytes (localPath, bytes); // writes to local storage }; var url = new Uri("https://www.xamarin.com/content/images/pages/branding/assets/xamagon.png"); webClient.DownloadDataAsync(url); } } }
Answers
Many ways to go about this...
Most Effort) Manually use System.Web to download and then write dependencies for each platform to save them.
Medium Effort) Manually use System.Web to download and then use PCLStorage to bypass the need to write dependencies.
Lazy Mans Route) Use Akavache and its extension method LoadImageFromUrl, then either use it to save to SQLite or use PCLStorage to save to disk.
Full props to Paul Betts and Daniel Plaisted for their plugins!
https://github.com/dsplaisted/PCLStorage
https://github.com/akavache/Akavache
by using WebClient in Android and Ios using Dependencies
in pcl
write a button click event
and also create a dependency service
in android and in ios
What code must be present in IDownloadService interface? Can you help me....