Ejemplo n.º 1
0
            public async Task <Windows.Networking.BackgroundTransfer.UploadOperation> UploadBackgroundAsync(Windows.Storage.StorageFile sourceFile,
                                                                                                            string containerName, string blobName, Action <Windows.Networking.BackgroundTransfer.UploadOperation> progressCallback = null)
            {
                var properties = await sourceFile.GetBasicPropertiesAsync();

                if (properties.Size > (1024 * 1024 * 64))
                {
                    throw new Exception("File cannot be larger than 64MB");
                }

                var permissions = Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPermissions.Write;
                var container   = this.Parent.GetContainer(containerName);
                var signature   = this.GetSas(permissions, TimeSpan.FromMinutes(5), container.Name, blobName);
                var uploader    = new Windows.Networking.BackgroundTransfer.BackgroundUploader
                {
                    TransferGroup = Windows.Networking.BackgroundTransfer.BackgroundTransferGroup.CreateGroup(_groupName)
                };

                uploader.SetRequestHeader("Filename", sourceFile.Name);
                var upload = uploader.CreateUpload(signature, sourceFile);

                if (progressCallback == null)
                {
                    return(await upload.StartAsync());
                }
                else
                {
                    return(await upload.StartAsync().AsTask(new Progress <Windows.Networking.BackgroundTransfer.UploadOperation>(progressCallback)));
                }
            }
Ejemplo n.º 2
0
        public async System.Threading.Tasks.Task UploadOpAsync(Uri uriInput, StorageFile file)
        {
            Windows.Networking.BackgroundTransfer.UploadOperation upload = null;
            //var promise = null;


            try
            {
                Uri uri = uriInput;
                Windows.Networking.BackgroundTransfer.BackgroundUploader uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader();

                // Set a header, so the server can save the file (this is specific to the sample server).
                uploader.SetRequestHeader("/Assets/", file.Name);

                // Create a new upload operation.
                upload = uploader.CreateUpload(uri, file);

                // Start the upload and persist the promise to be able to cancel the upload.
                upload = await upload.StartAsync();
            }
            catch
            {
            }
        }
Ejemplo n.º 3
0
            public async Task<Windows.Networking.BackgroundTransfer.UploadOperation> UploadBackgroundAsync(Windows.Storage.StorageFile sourceFile,
                string containerName, string blobName, Action<Windows.Networking.BackgroundTransfer.UploadOperation> progressCallback = null)
            {
                var properties = await sourceFile.GetBasicPropertiesAsync();
                if (properties.Size > (1024 * 1024 * 64))
                    throw new Exception("File cannot be larger than 64MB");

                var permissions = Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPermissions.Write;
                var container = this.Parent.GetContainer(containerName);
                var signature = this.GetSas(permissions, TimeSpan.FromMinutes(5), container.Name, blobName);
                var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader
                {
                    TransferGroup = Windows.Networking.BackgroundTransfer.BackgroundTransferGroup.CreateGroup(_groupName)
                };
                uploader.SetRequestHeader("Filename", sourceFile.Name);
                var upload = uploader.CreateUpload(signature, sourceFile);
                if (progressCallback == null)
                    return await upload.StartAsync();
                else
                    return await upload.StartAsync().AsTask(new Progress<Windows.Networking.BackgroundTransfer.UploadOperation>(progressCallback));
            }