Exemple #1
0
        public async Task <MediaFileInfo> ReplaceFileAsync(MediaFile file, Stream inStream, string newFileName)
        {
            Guard.NotNull(file, nameof(file));
            Guard.NotNull(inStream, nameof(inStream));
            Guard.NotEmpty(newFileName, nameof(newFileName));

            var fileInfo = ConvertMediaFile(file);
            var pathData = CreatePathData(fileInfo.Path);

            pathData.FileName = newFileName;

            var storageItem = ProcessFile(ref file, pathData, inStream, false, DuplicateFileHandling.Overwrite, MimeValidationType.MediaTypeMustMatch);

            using (var scope = new DbContextScope(_fileRepo.Context, autoCommit: false))
            {
                try
                {
                    await _storageProvider.SaveAsync(file, storageItem);

                    await scope.CommitAsync();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
            }

            return(fileInfo);
        }
Exemple #2
0
        public async Task <MediaFileInfo> ReplaceFileAsync(MediaFile file, Stream inStream, string newFileName)
        {
            Guard.NotNull(file, nameof(file));
            Guard.NotNull(inStream, nameof(inStream));
            Guard.NotEmpty(newFileName, nameof(newFileName));

            var fileInfo = ConvertMediaFile(file);
            var pathData = CreatePathData(fileInfo.Path);

            pathData.FileName = newFileName;

            var result = await ProcessFile(file, pathData, inStream, false, DuplicateFileHandling.Overwrite, MimeValidationType.MediaTypeMustMatch);

            try
            {
                await _storageProvider.SaveAsync(result.File, result.StorageItem);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            return(fileInfo);
        }