Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
 public Task CopyToAsync(Stream outputStream, CancellationToken cancellationToken = default) => _file
 .CopyToAsync(outputStream, cancellationToken);
Esempio n. 5
0
 protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
 {
     return(_file.CopyToAsync(stream));
 }