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

Question

Question

Converting Entry into Binary Data

asked on October 9

Hi Everyone,

I have close to zero experience using SDK Scripts so I was wondering if anyone can show me how to convert an Entry into Binary Data.

The reason for doing this is because I need to send this file through HTTP Form Request as shown below. 

It would be nice if the files are stored in the db as binary data already but I believe that is not the case.

Any help is greatly appreciated!

0 0

Replies

replied on October 9 Show version history

It depends on how the target service wants the data.

It can be as simple as this:

var de = new DocumentExporter();
var docInfo = Document.GetDocumentInfo(entryId, session);
var ms = new MemoryStream();

de.ExportPdf(docInfo, docInfo.AllPages, PdfExportOptions.IncludeText, ms);
var base64String = Convert.ToBase64String(ms.ToArray());

Then you can stick the string into a token and send it to your service. This will only work if the service accepts files as Base 64 strings. Otherwise you might need to encode it another way.

2 0
replied on October 9

Hi Devin,

Thanks for your response! We are sending binary multipart formdata as base64.

I tried using a slightly modified version of your code but got an error. Perhaps, there's something wrong with my version of the code.  Here's what I used:

Here's what the Form Post Activity looks like:

The error states that we have an "InvalidObject"

So I looked into the Token Value returned by from the SDK activity and it's like this. I'm not sure if this looks right. 

Once again, thank you for your help and I'd appreciate any sort of pointers.

Best regards,
Kentaro 

0 0
replied on October 10 Show version history

While the DocumentData value looks like it is probably correct, I would change your code to use the Workflow connection.  Then you will not have to deal with logging into the repository.  Also, I would implement "using" blocks in the code to make it cleaner and reduce potential memory leakage.

The code looks something like

            String base64String = null;
            try
            {
                // Get EntryID from the FindEntry activity
                int iDocID = (int)GetTokenValue("FindEntry_OutputEntry_ID");
                // Get the document using the Workflow connection
                using (DocumentInfo DocInfo = Document.GetDocumentInfo(iDocID, RASession))
                {
                    // Create MemoryStream to hold exported document
                    using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                    {
                        // Create DocumentExporter object
                        DocumentExporter de = new DocumentExporter();
                        // Export to PDF in MemoryStream
                        de.ExportPdf(DocInfo, DocInfo.AllPages, PdfExportOptions.IncludeText, ms);
                        // Write MemoryStream data to Base64 string
                        base64String = Convert.ToBase64String(ms.ToArray());
                    }
                }
            }
            catch (Exception ex)
            {
                // Report exception message
                WorkflowApi.TrackError(ex.Message);
                // Set return value to null
                base64String = null;
            }
            // Return the Base64 String
            SetTokenValue("DocumentData", base64String);

 

2 0
replied on October 10 Show version history

The error you get seems like the web form is expecting a path or URL to the document and not a base64 string.

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

Sign in to reply to this post.