@Dmitriy.Sorokin
We deployed this on a different environment (vNext) and it seems this is the real error when saving PSB files with 2GB.
Exception of type ‘System.OutOfMemoryException’ was thrown. Show
System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown. at System.IO.MemoryStream.set_Capacity(Int32 value) at System.IO.MemoryStream.EnsureCapacity(Int32 value) at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count) at .Write(Byte[] , Int32 , Int32 ) at Aspose.PSD.FileFormats.Psd.Layers.ChannelInformation.(StreamContainer , Boolean ) at Aspose.PSD.FileFormats.Psd.Layers.LayerResources.LrXxResource.(StreamContainer , Int32 ) at Aspose.PSD.FileFormats.Psd.Layers.LayerResources.LrXxResource.(Int32 ) at .(Int32 ) at .(Int64 ) at .(StreamContainer , Int32 , IColorPalette , , Int32 ) at Aspose.PSD.FileFormats.Psd.PsdImage.SaveData(Stream stream) at Aspose.PSD.DataStreamSupporter.Save(Stream stream) at Aspose.PSD.DataStreamSupporter.Save(String filePath) at Adam.Core.MediaEngines.AsposePsdMediaEngine.UpdateXmpMetadata(UpdateXmpMetadataMediaAction action) at Adam.Core.MediaEngines.MediaManager.RunAction(MediaAction action, IMediaEngine engine, Exception& exception) at Adam.Core.MediaEngines.MediaManager.RunInternal(IEnumerable1 engines, IEnumerable
1 actions) at Adam.Core.Orders.UpdateXmpMetadataOrderTargetAction.OnExecute() at Adam.Core.Orders.OrderRunner.ExecuteRegisteredActions()
Which is why we didn’t encountered this in our local environment stated from my previous post as my local environment have higher specs from the other hosted environment.
Here is the code
private bool UpdateXmpMetadata(UpdateXmpMetadataMediaAction action)
{
if (!string.IsNullOrEmpty(action.XmpMetadataMapping))
{
PsdImage img = null;
// First attempt to load the PSD/PSB file
try
{
var loadOptions = new PsdLoadOptions()
{
BufferSizeHint = 50 * 1048576,
ReadOnlyMode = false,
LoadEffectsResource = false, // Faster loading by skipping layer effects
UseDiskForLoadEffectsResource = true // Prevents high RAM usage for large files
};
using (var inputStream = File.OpenRead(action.Path))
{
img = (PsdImage)Image.Load(inputStream, loadOptions);
}
}
catch (ImageLoadException e)
{
// Cannot suppport PSD/PSB files with Multichannel or Duotone color mode at this time due to known Aspose bug
if (e.Message.ToLower().Contains("image") && e.InnerException.Message.ToLower().Contains("color mode") && e.InnerException.Message.ToLower().Contains("compression"))
{
throw new MediaEngineException("PSD/PSB files with Multichannel or Duotone color mode are not supported.", false);
}
}
catch (Exception)
{
// Something unexpected went wrong while loading
throw;
}
// Since we loaded successfully, process it
using (img)
{
// Cannot suppport PSD/PSB files with Lab color mode which have 16 bits per channel at this time due to known Aspose bug
if (img.ColorMode == ColorModes.Lab && img.BitsPerChannel == 16)
{
throw new MediaEngineException("PSD/PSB files with Lab color mode which have 16 bits per channel are not supported.", false);
}
// Cannot suppport PSD/PSB files with CMYK color mode which have less than 4 or more than 5 channels at this time due to known Aspose bug
if (img.ColorMode == ColorModes.Cmyk && (img.ChannelsCount < 4 || img.ChannelsCount > 5))
{
throw new MediaEngineException("PSD/PSB files with CMYK color mode must have 4 or 5 channels.", false);
}
// Cannot suppport PSD/PSB files with RGB/Lab color mode which have less than 3 or more than 4 channels at this time due to known Aspose bug
if ((img.ColorMode == ColorModes.Rgb || img.ColorMode == ColorModes.Lab) && (img.ChannelsCount < 3 || img.ChannelsCount > 4))
{
throw new MediaEngineException("PSD/PSB files with RGB/Lab color must have 3 or 4 channels.", false);
}
XDocument xmpMapping = XDocument.Parse(action.XmpMetadataMapping);
// Getting the xmp metadata
XmpPacketWrapper xmpData = img.XmpData;
if (xmpData == null)
{
// Create xmp metadata if the image doesn't contains any xmp data.
XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString());
XmpTrailerPi xmpTrailer = new XmpTrailerPi(true);
XmpMeta xmpMeta = new XmpMeta();
xmpData = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);
img.XmpData = xmpData;
}
foreach (var mapping in xmpMapping.Descendants("xmpMapping").Elements("add"))
{
var xmpNamespace = mapping.Attribute("namespace").Value;
var xmpName = mapping.Attribute("name").Value;
var xmpPrefix = mapping.Attribute("prefix").Value;
var xmpValue = mapping.Value;
if (xmpData.ContainsPackage(xmpNamespace))
{
// Update or add XMP property value in existing namespace
foreach (var xmpPackage in xmpData.Packages)
{
if (xmpPackage.NamespaceUri.Trim().ToLower() == xmpNamespace.Trim())
{
if (xmpPackage.ContainsKey(xmpPackage.Prefix + ":" + xmpName))
{
xmpPackage[(xmpPackage.Prefix + ":" + xmpName)] = xmpValue;
}
else
{
xmpPackage.AddValue(xmpPackage.Prefix + ":" + xmpName, xmpValue);
}
}
}
}
else
{
// Create XMP namespace, since it does not yet exist
XmpBasicPackage xmp = new XmpBasicPackage(xmpPrefix, xmpNamespace);
xmp.AddValue(xmpPrefix + ":" + xmpName, xmpValue);
xmpData.AddPackage(xmp);
}
}
img.Save(action.OutputPath);
}
return true;
}
return false;
}
If this would be a environment issue, what would be the minimum specs to prevent this such issue or do you think this is a code base issue on the side of Aspose.PSD?
Additional note on this. The app is hosted in a containerized environment with this specs below
AKS node:
OS version: Windows Server 2022 Datacenter
Kubelet version: v1.31.5
AKS pod specs:
resources:
limits:
memory: 10Gi
requests:
cpu: 800m
memory: 1Gi