We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Stream into MapiAttachment

I have a MapiAttachment object for which I’d like to set the body of the attachment, which I have coming from a network stream in blocks. I appreciate I can accumulate all the blocksof data into a byte[] then assign it using MapiAttachment.BinaryData = mybytes but is there any way I can make use of the fact that the data is coming in chunks in order to avoid having that data all in memory at once?

For instance, I would like to give the stream to the MapiAttachment and let it read the data, such as MapiAttachment.BinaryDataFromStream(mystream), or perhaps append the blocks to the existing BinaryData (but I suspect that would cause more memory allocation).

I appreciate eventually all the attachment data is going to be in memory in the MapiAttachment instance, I’m just trying to reduce the number of duplicates to be memory efficient.

The same question applies to the body of an email and MapiMessage.Body.

Hello, @RobertHunt

is there any way I can make use of the fact that the data is coming in chunks in order to avoid having that data all in memory at once?

Unfortunately, Aspose.Email doesn’t provide this functionality.

It seems that the our internal implementation of MapiAttachment.BinaryDataFromStream(mystream) will consume about the same memory amount as your external implementation of this functionality. Because ultimately MapiAttachment keeps the data in a byte array.

Thanks.

That’s what I thought but thanks for the clarification.