public async Task <bool> CreateFileAsync(IFile file, AlphaNumericString tag, CancellationToken cancellationToken = default) { if (file == null) { throw new ArgumentNullException(nameof(file)); } var tagPath = GetTagPath(tag); if (!Directory.Exists(tagPath)) { Directory.CreateDirectory(tagPath); } var filePath = GetFilePath(tag, file); using (var fs = File.Open(filePath, FileMode.Create)) { await file.CopyToAsync(fs, cancellationToken); await fs.FlushAsync(cancellationToken); } return(true); }
private static async Task <string> SaveImageAsync(IFile file, string imageFolder) { var uniqueFileName = Guid.NewGuid() + "_" + file.FileName; var filePath = Path.Combine(imageFolder, uniqueFileName); await using var fileStream = new FileStream(filePath, FileMode.Create); await file.CopyToAsync(fileStream); return(uniqueFileName); }
public async Task AddAsync(IFile file) { var metadata = FileMetadata.FromFile(file); await _metadataRepository.AddAsync(metadata); using (var stream = _documentStore.OpenWrite(file.Folder, file.ResourceId)) { await file.CopyToAsync(stream); // await .AddAsync(file.Folder, metadata.ResourceId, file.CopyToAsync); } }
public Task CopyToAsync(Stream outputStream, CancellationToken cancellationToken = default) => _file .CopyToAsync(outputStream, cancellationToken);
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context) { return(_file.CopyToAsync(stream)); }