public async Task <IFileInfo> WriteFileAsync(Stream stream, string path, IWriteFileOptions options) { if (options is null) { throw new ArgumentNullException(nameof(options)); } if (!options.OverrideIfExists && await FileExistsAsync(path)) { throw new FileAlreadyExistsException(path); } using var client = GetClient(); var request = new PutObjectRequest { BucketName = this.bucketName, InputStream = stream, Key = path }; if (options is IS3FileWriteOptions s3FileWriteOptions) { if (s3FileWriteOptions.Acl != null) { request.CannedACL = new S3CannedACL(s3FileWriteOptions.Acl); } } var result = await client.PutObjectAsync(request); var file = await GetFileInfoByPath(path); return(file); }
public async Task <IFileInfo> WriteFileAsync(Stream stream, string path, IWriteFileOptions options) { if (options is null) { throw new ArgumentNullException(nameof(options)); } if (!options.OverrideIfExists && await FileExistsAsync(path)) { throw new FileAlreadyExistsException(path); } CreateDirectoryIfNotExisting(path); if (stream.CanSeek && stream.Position != 0) { stream.Seek(0, SeekOrigin.Begin); } using (var fileStream = new FileStream(path, FileMode.CreateNew, FileAccess.Write)) { await stream.CopyToAsync(fileStream); fileStream.Close(); } var fileInfo = new FileInfo(path); var physicalinfo = new PhysicalFileInfo(fileInfo); return(physicalinfo); }
public async Task <IFileInfo> WriteFileAsync(byte[] bytes, string path, IWriteFileOptions options) { if (options is null) { throw new ArgumentNullException(nameof(options)); } if (!options.OverrideIfExists && await FileExistsAsync(path)) { throw new FileAlreadyExistsException(path); } var container = GetContainer(); var blob = container.GetBlockBlobReference(path); await blob.UploadFromByteArrayAsync(bytes, 0, bytes.Length); return(new AzureBlobFileInfo(blob)); }
public async Task <IFileInfo> WriteFileAsync(byte[] bytes, string path, IWriteFileOptions options) { if (options is null) { throw new ArgumentNullException(nameof(options)); } if (!options.OverrideIfExists && await FileExistsAsync(path)) { throw new FileAlreadyExistsException(path); } CreateDirectoryIfNotExisting(path); File.WriteAllBytes(path, bytes); var fileInfo = new FileInfo(path); var physicalinfo = new PhysicalFileInfo(fileInfo); return(physicalinfo); }
public async Task <IFileInfo> WriteFileAsync(string sourcePath, string path, IWriteFileOptions options) { if (options is null) { throw new ArgumentNullException(nameof(options)); } if (!options.OverrideIfExists && await FileExistsAsync(path)) { throw new FileAlreadyExistsException(path); } CreateDirectoryIfNotExisting(path); System.IO.File.Copy(sourcePath, path, options.OverrideIfExists); var fileInfo = new FileInfo(path); var ret = new PhysicalFileInfo(fileInfo); return(ret); }
public async Task <IFileInfo> WriteFileAsync(Stream stream, string path, IWriteFileOptions options) { if (options is null) { throw new ArgumentNullException(nameof(options)); } if (!options.OverrideIfExists && await FileExistsAsync(path)) { throw new FileAlreadyExistsException(path); } if (stream.CanSeek && stream.Position != 0) { stream.Seek(0, SeekOrigin.Begin); } var container = GetContainer(); var blob = container.GetBlockBlobReference(path); await blob.UploadFromStreamAsync(stream); return(new AzureBlobFileInfo(blob)); }
public Task <IFileInfo> WriteFileAsync(byte[] bytes, string path, IWriteFileOptions options) { return(WriteFileAsync(new MemoryStream(bytes), path, options)); }
public async Task <IFileInfo> WriteFileAsync(string sourcePath, string path, IWriteFileOptions options) { using var fileStream = new FileStream(sourcePath, FileMode.Open, FileAccess.Read); return(await WriteFileAsync(fileStream, path, options)); }