示例#1
0
 public Task WriteItemBytesAsync(string itemName, byte[] bytes) => Task.Run(() =>
 {
     var fullName = GetItemFileName(itemName);
     if (FSProvider.Exists(fullName))
     {
         FSProvider.Delete(fullName);
     }
     FSProvider.WriteAllBytes(fullName, bytes);
 });
        public async Task <string> SaveFileAsync(IFormFile image, CancellationToken cancellationToken)
        {
            string path = Path.Combine(_environment.WebRootPath, "Resourses", "Products");

            if (!_fileProvider.Exists(path))
            {
                _fileProvider.CreateDirectory(path);
            }

            string fileExtencion = Path.GetExtension(image.FileName);
            string fileName      = Path.GetFileName(Guid.NewGuid().ToString() + '.' + fileExtencion);

            using (Stream stream = _fileStreamFactory.CreateFileStream(Path.Combine(path, fileName), FileMode.Create))
            {
                await image.CopyToAsync(stream, cancellationToken);
            }

            return("/Resourses/Products/" + fileName);
        }