/// <inheritdoc/> public IFileMetaData Create(string fileName, string fileType, Stream stream, bool throwOnException = true) { try { ValidateRules(_fileServiceConfig, stream, fileType, fileName); IFileMetaData fileMetaData = new FileMetaData(_fileServiceConfig, stream, fileName, fileType, false); return(fileMetaData); } catch (Exception ex) { if (throwOnException) { throw ex; } return(null); } }
/// <inheritdoc/> public IFileMetaData Update(string fileName, string fileType, byte[] bytes, bool throwOnException = true, bool throwOnNotFound = true) { try { ValidateRules(_fileServiceConfig, bytes, fileType, fileName); string absolutePath = _fileServiceConfig.RootDirectory + Path.DirectorySeparatorChar + fileType + Path.DirectorySeparatorChar + fileName; Delete(fileName, fileType, throwOnException, true); File.WriteAllBytes(absolutePath, bytes); IFileMetaData fileMetaData = new FileMetaData(_fileServiceConfig, fileName, fileType, false); return(fileMetaData); } catch (Exception ex) { if (throwOnException) { throw ex; } return(null); } }
/// <inheritdoc/> public async Task <IFileMetaData> UpdateAsync(string fileName, string fileType, Stream stream, bool throwOnException = true, bool throwOnNotFound = true) { try { ValidateRules(_fileServiceConfig, stream, fileType, fileName); string absolutePath = _fileServiceConfig.RootDirectory + Path.DirectorySeparatorChar + fileType + Path.DirectorySeparatorChar + fileName; Delete(fileName, fileType, throwOnException, true); using (var fstream = new FileStream(absolutePath, FileMode.Open, FileAccess.Write)) await stream.CopyToAsync(fstream); IFileMetaData fileMetaData = new FileMetaData(_fileServiceConfig, fileName, fileType, false); return(fileMetaData); } catch (Exception ex) { if (throwOnException) { throw ex; } return(null); } }