Ushahidi.Model.Models.Media.Download C# (CSharp) Méthode

Download() public static méthode

Download image from server
public static Download ( string sourceURL, string destinationFilePath ) : bool
sourceURL string source url
destinationFilePath string destination filepath
Résultat bool
        public static bool Download(string sourceURL, string destinationFilePath)
        {
            try
            {
                Log.Info("DataManager.DownloadImage", "Source: {0} Destination: {1}", sourceURL, destinationFilePath);
                FileInfo fileInfo = new FileInfo(destinationFilePath);
                if (fileInfo.Exists == false || fileInfo.Length == 0)
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sourceURL);
                    ServicePointManager.CertificatePolicy = Internet.AcceptAllCertificatePolicy();
                    request.Credentials = CredentialCache.DefaultCredentials;
                    request.AllowAutoRedirect = true;
                    request.ReadWriteTimeout = 5000;
                    request.Method = "GET";
                    request.Timeout = 5000;
                    request.KeepAlive = false;
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        using (Stream stream = response.GetResponseStream())
                        {
                            using (Image image = new Bitmap(stream))
                            {
                                image.Save(destinationFilePath, ImageFormat.Jpeg);
                            }
                        }
                    }
                    return true;
                }
            }
            catch (Exception ex)
            {
                Log.Exception("DataManager.DownloadImage", "Exception: {0}", ex.Message);
            }
            return false;
        }