public Exception Download(DownloadInfo downloadInfo) { IDownload sourceFilter = null; try { downloadThread = System.Threading.Thread.CurrentThread; this.downloadResult = 0; this.downloadFinished = false; this.cancelled = false; sourceFilter = (IDownload) new MPUrlSourceSplitter(); String url = UrlBuilder.GetFilterUrl(downloadInfo.Util, downloadInfo.Url); IDownload downloadFilter = (IDownload)sourceFilter; int result = downloadFilter.DownloadAsync(url, downloadInfo.LocalFile, this); // throw exception if error occured while initializing download Marshal.ThrowExceptionForHR(result); while (!this.downloadFinished) { long total = 0; long current = 0; if (downloadFilter.QueryProgress(out total, out current) >= 0) { // succeeded or estimated value downloadInfo.DownloadProgressCallback(total, current); } // sleep some time System.Threading.Thread.Sleep(100); if (this.cancelled) { downloadFilter.AbortOperation(); this.downloadFinished = true; this.downloadResult = 0; } } // throw exception if error occured while downloading Marshal.ThrowExceptionForHR(this.downloadResult); return(null); } catch (Exception ex) { return(ex); } finally { if (sourceFilter != null) { Marshal.ReleaseComObject(sourceFilter); } } }
private static async Task UploadDownloadTransfer(AmazonS3Client client, string bucketName, string objectName) { Console.WriteLine(); Console.WriteLine("Using the Transfer API"); //The Transfer API is an easy-to-use API for building requests. IUpload upload = client.CreateUpload(bucketName, objectName) .WithAccessControl(ObjectCannedAcl.PublicReadWrite) .WithCacheControl(CacheControlType.NoCache) .WithEncryption(); PutObjectResponse putResp = await upload.UploadStringAsync("Hello World!"); if (putResp.IsSuccess) { Console.WriteLine("Successfully uploaded the object"); //Download string IDownload download = client.CreateDownload(bucketName, objectName) .WithRange(0, 5); //Adjust this to return only part of the string GetObjectResponse getResp = await download.DownloadAsync(); if (getResp.IsSuccess) { Console.WriteLine("Success! The object contained: " + await getResp.Content.AsStringAsync()); } else { Console.WriteLine("Failed to download the object"); } } else { Console.WriteLine("Failed to upload the object"); } }