public async void InitiateFileUploading() { StorageFolder picturesFolder = KnownFolders.DocumentsLibrary; //string path = Windows.Storage.ApplicationData.Current.LocalFolder.Path; //string PhotoPath = path.Substring(0, path.IndexOf("AppData")) + picturesFolder.Name; //Windows.Storage.StorageFolder store; //FileOpenPicker openPicker = new FileOpenPicker(); //openPicker.ViewMode = PickerViewMode.Thumbnail; ////openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; //openPicker.FileTypeFilter.Add(".jpg"); //openPicker.FileTypeFilter.Add(".jpeg"); //openPicker.FileTypeFilter.Add(".png"); //StorageFile f = await openPicker.PickSingleFileAsync(); // IReadOnlyList<StorageFile> files = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFilesAsync(); Windows.Storage.StorageFolder store=await Windows.Storage.ApplicationData.Current.RoamingFolder.GetFolderAsync("Upload"); // Windows.Storage.StorageFolder store = await StorageFolder.GetFolderFromPathAsync(@"c:\Carl"); IReadOnlyList<StorageFile> files = await store.GetFilesAsync(); // string[] filePaths = System.IO.Path.GetFiles(@"c:\MyDir\"); //progressbar1.Value = 30; // IReadOnlyList<StorageFile> files = await picturesFolder.GetFilesAsync(); // IReadOnlyList<StorageFolder> fol =await picturesFolder.GetFoldersAsync(); //string bucketname = "TestingUploadS3"; List<FileUploadCompleted> listUploadFiles = new List<FileUploadCompleted>(); FileUploadCompleted uploadfile; // var storage = new Setting<List<FileUploadCompleted>>(); //await storage.SaveAsync("Statistics", null); foreach (var file in files) { uploadfile = new FileUploadCompleted(); // progressbar1.Value = 0; // AmazonFileBucketTransferUtil uploadTG = new AmazonFileBucketTransferUtil(bucketname, "key" + Guid.NewGuid().ToString(), file.Path); uploadfile.UploadStartTime = DateTime.Now; uploadfile.Name = file.Name; uploadfile.Url = "https://s3-us-east-1.amazonaws.com/"+ExistingBucketName+"/" + file.Name; //try //{ // System.IO.FileInfo f = new FileInfo(file.Path); // uploadfile.size=f.Length; //} //catch { } //uploadfile.size=file. // currentfile.Text = "Currently Uploading file: " + file.Name; await UploadFile(file.Name, file); uploadfile.UploadEndtime = DateTime.Now; listUploadFiles.Add(uploadfile); //await UpdateRDS(uploadfile,patientobj); // await storage.SaveAsync("Statistics", listUploadFiles); //progressbar1.Value = .currentStatus; } // currentfile.Text = "All files are successfully uploaded"; // notify.Text = ""; // await storage.SaveAsync("Statistics", listUploadFiles); }
//public async Task UploadFileAsync(string name, IStorageFile storageFile, FileUploadCompleted fileinfo) //{ // await Task.Factory.StartNew(() => UploadFile( name, storageFile, fileinfo)); //} public async void UploadFile(string name, IStorageFile storageFile, FileUploadCompleted fileinfo) { fileinfo.UploadStartTime = DateTime.Now; BasicAWSCredentials credentials = new BasicAWSCredentials("AKIAJTADDHY7T7GZXX5Q", "n4xV5B25mt7e6br84H2G9SXBx8eDYTQJgCxoaF49"); var s3Client = new AmazonS3Client(credentials, RegionEndpoint.USEast1); var transferUtilityConfig = new TransferUtilityConfig { ConcurrentServiceRequests = 5, MinSizeBeforePartUpload = 20 * MB_SIZE, }; try { using (var transferUtility = new TransferUtility(s3Client, transferUtilityConfig)) { var uploadRequest = new TransferUtilityUploadRequest { BucketName = ExistingBucketName, Key = name, StorageFile = storageFile, // Set size of each part for multipart upload to 10 MB PartSize = 10 * MB_SIZE, CannedACL = S3CannedACL.PublicRead }; uploadRequest.UploadProgressEvent += OnUploadProgressEvent; // fileinfo.Status = currentStatus.ToString(); try { await transferUtility.UploadAsync(uploadRequest); } catch { } // fileinfo.UploadEndtime = DateTime.Now; } } catch (AmazonS3Exception amazonS3Exception) { if (amazonS3Exception.ErrorCode != null && (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity"))) { // Console.WriteLine("Check the provided AWS Credentials."); // Console.WriteLine( // "For service sign up go to http://aws.amazon.com/s3"); } else { //Console.WriteLine( // "Error occurred. Message:'{0}' when writing an object" // , amazonS3Exception.Message); } } }