public void WriteOtherMediaBytes(Media media, MediaSaveLocation saveLocation) { //we need to save the file on file system if (media.Binary == null || !media.Binary.Any()) { throw new mobSocialException("Can't write empty bytes for picture"); } if (saveLocation == MediaSaveLocation.FileSystem) { //get the directory path from the relative path var directoryPath = ServerHelper.GetLocalPathFromRelativePath(_mediaSettings.OtherMediaSavePath); if (string.IsNullOrEmpty(media.SystemName)) { media.SystemName = Guid.NewGuid().ToString("n"); } var filePath = PathUtility.GetFileSavePath(directoryPath, media.SystemName); File.WriteAllBytes(filePath, media.Binary); //clear bytes media.Binary = null; media.LocalPath = filePath; } }
public void WritePictureBytes(Media picture, MediaSaveLocation pictureSaveLocation) { //we need to save the file on file system if (picture.Binary == null || !picture.Binary.Any()) { throw new mobSocialException("Can't write empty bytes for picture"); } if (pictureSaveLocation == MediaSaveLocation.FileSystem) { //get the directory path from the relative path var directoryPath = ServerHelper.GetLocalPathFromRelativePath(_mediaSettings.PictureSavePath); var fileExtension = PathUtility.GetFileExtensionFromContentType(picture.MimeType); if (string.IsNullOrEmpty(picture.SystemName)) { picture.SystemName = $"{Guid.NewGuid().ToString("n")}"; } var proposedFileName = $"{picture.SystemName}{fileExtension}"; var filePath = PathUtility.GetFileSavePath(directoryPath, proposedFileName); var imageFormat = PictureUtility.GetImageFormatFromContentType(picture.MimeType); _imageProcessor.WriteBytesToImage(picture.Binary, filePath, imageFormat); //clear bytes picture.Binary = null; picture.LocalPath = filePath; picture.ThumbnailPath = ServerHelper.GetRelativePathFromLocalPath(filePath); } }