Web Service that deliveres BLOB data

I wanted to be able to use the Record Link table in NAV to link to my attachments. Since that part of NAV is not customizable every attachment that I link to NAV needs to be accessible via URL.

So, when I import or scan a file into NAV it can be stored in a BLOB or I can store it in a customized external database. After storing the file I create a URL link to that file and insert that as a new link to any record in NAV. To complete this task I created a NAV Web Service that delivers the file as a base64 string. Here is the part of the code that encodes the BLOB stream to a BigText variable.
[code htmlscript=”false”]TempFile.CREATETEMPFILE;
TempFileName := TempFile.NAME;
TempFile.CLOSE;
TempFile.TEXTMODE(FALSE);
TempFile.CREATE(TempFileName);
TempFile.CREATEOUTSTREAM(OutStr);
DocumentStore.Blob.CREATEINSTREAM(InStr);
COPYSTREAM(OutStr,InStr);
TempFile.CLOSE;

CREATE(XMLDoc);
CREATE(ADOStream);
XMLNode := XMLDoc.createNode(‘element’, ‘ImageFile’, ‘SKYRR Signing’);
XMLNode.dataType := ‘bin.base64’;

ADOStream.Type := 1;
ADOStream.Open();
ADOStream.LoadFromFile(TempFileName);
XMLNode.nodeTypedValue := ADOStream.Read();
ADOStream.Close();

Document.ADDTEXT(XMLNode.text);

CLEAR(ADOStream);
CLEAR(XMLNode);
CLEAR(XMLDoc);
ERASE(TempFileName);[/code]
Then I created a aps.net website that can get the document both from this NAV Web Service and also from the customized database all based on the parameters passed with the URL.

Attached is a part of the NAV code and the website required to deliver the attachment.

WebSite

Attachment NAV Source Code

 

4 Replies to “Web Service that deliveres BLOB data”

  1. A few questions:

    1.
    How and through what function in NAV is the blob created ?

    2.
    The bigtext value “Document” is returned from the webservice?

    If it is a large file (blob) won’t that eat away all the memory?

  2. Hi Erik,

    1. The blob is usually created by importing a file. This file can for example be an image, an Excel Document, PDF Document or an XML file. It is also possible to create the blob with XML Port or by writing to an out stream.

    2. The bigtext variable will contain a base64 version of the document. This is a similar method that is used when attaching files to an email message. You should be able to use similar rule, that it, files to big for email will also be to big for this web service.

  3. The CREATE of XMLDoc Automation cannot be done in NAV 2015 by Webservices, resulting in an error that no client callback is possible (apperently because NAV wants to pop up a dialog to assure that the CREATE of an unknown Automation is allowed by the user). I read advice in other forums that the dotnet versions of XMLDoc and XMLNode should be used instead. But I don’t find a possibility to set the DataType in an XMLNode to Base64 ´with the dotnet Version. Do you know how to do that? Thank you in advance.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.