You are viewing limited content. For full access, please sign in.

Question

Question

Should I use MemoryStream

SDK
asked on May 26, 2020

Hi all. 

Years ago a followed a sample to export PDF files. It saves them to the local [webservice] server then sends them back as Base64 with he following lines.

BinaryReader binReader = new BinaryReader(File.Open(strLocalFile, FileMode.Open, FileAccess.Read));
binReader.BaseStream.Position = 0;
byte[] binFile = binReader.ReadBytes(Convert.ToInt32(binReader.BaseStream.Length));
binReader.Close();
return binFile;

However while researching how to export a single JPG; I kept seeing reference to a "MemoryStream".  My impression is that this could take [(exporter.ExportPage(docInfo, 1, strLocalFile);] and with less steps send it right back to the requester as a JPG? However no code samples were complete.

So is there a better way to send things back? Can I use memorystream like I am thinking? Send a jpg directly when called? Maybe even not saving it to the local drive first??

What I've been doing works, but that doesn't mean I've been doing right/best.
Thanks for any input.

 

 

 

0 0

Answer

SELECTED ANSWER
replied on May 26, 2020 Show version history

Switching to MemoryStream will make your code faster because the file contents will be read directly into memory without the intermediate step of storing on disk:

 

using (MemoryStream imageStream = new MemoryStream())
{
    docExporter.PageFormat = DocumentPageFormat.Jpeg;
    docExporter.ExportPage(doc, pageNumber, imageStream);
    return imageStream.ToArray();
}

 

1 0

Replies

replied on May 26, 2020

Thanks Robert for guiding me to the right path.

I've been searching too,
To get what I'm after I may need to combine with a ASHX file?
This thread has me thinking about it.
https://answers.laserfiche.com/questions/57193/any-sample-code-on-using-sdk-to-retrieve-image?sort=oldest

I'd like for a user to just have "<img src='LFImage.ashx?documentid=1111111' width="550" height="800" />" on their html page, and the image would be injected there live. So they wouldn't need anything special or knowledge of my service, that ASHX page would make the call to my web service and then forward the stream as if it was simply a JPG file.

No sure yet how to do this or I'm looking at it wrong, I have a lot to figure out yet.

Thanks,

 

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.