When we upload a image to litium media module we have a broker that is supposed to check if the file already exists and if so replace the file. Since we want to keep existsing links to the file we want to have the same behaviour as if a duplicate file was uploaded via lite backoffice.
How do one copy the blob from the new file to the old file blob?
We have tried looking at blobservice and blobextensions to get the blobs and copy from the new file to the new but not sure if this is the wrong approach or if we done something wrong since the old file is not updated in litium backoffice even if the code runs without errors.
var blobContainer = blobService.Create(File.BlobAuthority);
using (securityContextService.ActAsSystem(nameof(FileBroker)))
{
var newFileBlobContainer = blobService.Get(newfile.BlobUri);
var newFileBlob = newFileBlobContainer.GetDefault();
var existingFileClone = existingFile.MakeWritableClone();
var existingFileBlobContainer = blobService.Get(existingFileClone.BlobUri);
var existingFileBlob = existingFileBlobContainer.GetDefault();
newFileBlob.CopyTo(existingFileBlob);
// existingFileClone.BlobUri = existingFile.BlobUri;
existingFileClone.FileSize = newfile.FileSize;
fileService.Update(existingFileClone);
fileService.Delete(file);
}
Litium version: 8.20.3