/// <summary>Uploads the specified file.</summary> /// <param name="file">The file to upload.</param> /// <returns>The URI that will be used to <see cref="DownloadAsync">download</see> the file.</returns> public async Task <Uri> UploadAsync(ITransferableFile file) { await Container.CreateIfNotExistsAsync(); var blob = Container.GetBlockBlobReference(file.Name); blob.Properties.ContentType = await file.GetMimeTypeAsync(); await blob.SetPropertiesAsync(); await blob.UploadFromStreamAsync(await file.GetContentAsync()); return(new Uri(file.Name)); }
/// <summary>Uploads the specified chunk.</summary> /// <param name="id">The identifier of the chunk.</param> /// <param name="chunk">The chunk.</param> public async Task <Uri> UploadChunkAsync(int id, ITransferableFile chunk) { await Container.CreateIfNotExistsAsync(); var blob = Container.GetBlockBlobReference(chunk.Name); var sid = string.Format( CultureInfo.InvariantCulture, "{1:X8}", id ); await blob.PutBlockAsync(sid, await chunk.GetContentAsync(), null); return(new Uri(chunk.Name)); }
/// <summary>Uploads the specified file.</summary> /// <param name="file">The file to upload.</param> /// <returns>The URI that will be used to <see cref="FileTransferClient.DownloadAsync">download</see> the file.</returns> protected override async Task <Uri> DoUploadAsync(ITransferableFile file) { var path = Path.Combine(BaseAddress.LocalPath, file.Name); var dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (var dfs = File.Create(path, 1024, FileOptions.Asynchronous | FileOptions.WriteThrough)) using (var sfs = await file.GetContentAsync()) await sfs.CopyToAsync(dfs); return(new Uri(path)); }
/// <summary>Uploads the specified file.</summary> /// <param name="file">The file to upload.</param> /// <returns>The URI that will be used to <see cref="DownloadAsync">download</see> the file.</returns> protected abstract Task <Uri> DoUploadAsync(ITransferableFile file);
/// <summary>Uploads the specified file.</summary> /// <param name="file">The file to upload.</param> /// <returns>The URI that will be used to <see cref="DownloadAsync">download</see> the file.</returns> public Task <Uri> UploadAsync(ITransferableFile file) { return(DoUploadAsync(file)); }