I am trying to use MagicImage to convert HEIC to JPEG, so my newFile.Data contain byte[] of image that was sent to server. So I am pretty sure that my code correct, but when I am sending image to server i.e to web it uploads in HEIC format but i need it in jpeg. So I am stuck here and can't figure out what i need to do
using (var image = new MagickImage(newFile.Data))
{
// Sets the output format to jpeg
image.Format = MagickFormat.Jpeg;
// Create byte array that contains a jpeg file
byte[] data = image.ToByteArray();
}
var currentFiles =
_clientFileService.Value.GetFilesByClient(clientId).Where(x => x.ClientFileType == type).Select(x => x.Id).ToList();
_clientFileService.Value.MultipleDelete(currentFiles, null);
_clientFileService
.Value
.AddFile(
new ClientFile
{
Data = newFile.Data, // How can I pass MagickImage to newFile.Data
Guid = Guid.NewGuid()
});
CodePudding user response:
I think you'll need to use the data of MagikImage in the fileService:
byte[] data = null;
using (var image = new MagickImage(newFile.Data))
{
// Sets the output format to jpeg
image.Format = MagickFormat.Jpeg;
// Create byte array that contains a jpeg file
data = image.ToByteArray();
}
var currentFiles = _clientFileService.Value
.GetFilesByClient(clientId)
.Where(x => x.ClientFileType == type)
.Select(x => x.Id)
.ToList();
_clientFileService.Value.MultipleDelete(currentFiles, null);
_clientFileService
.Value
.AddFile(new ClientFile
{
Data = data
Guid = Guid.NewGuid()
});