Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

How to insert DataUri in Text to Blob in NAV 2018 AL

Posted on by 3,957

Hi,

I've created a JavaScript function ControlAdd-in which return a DataUri in Text, and save it in BLOB using AL extensions. 
I've tried using Text Datatype but the uri exceeds 250 characters. Thus, cannot store it as a text.

*This post is locked for comments

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: How to insert DataUri in Text to Blob in NAV 2018 AL

    Yes Azure Function could be a solution for converting MemoryStream. In NAV 2018 you've also codeunit 704 for handling MemoryStream objects.

  • Olister Rumao Profile Picture
    Olister Rumao 3,957 on at
    RE: How to insert DataUri in Text to Blob in NAV 2018 AL

    Hi Stefano,

    It worked. But I'm facing another issue as to convert the DataUri to Memory Stream. Can this be done through azure functions assuming that we can convert in some way and then store it as a BLOB.

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: How to insert DataUri in Text to Blob in NAV 2018 AL

    You can save the DataUri in a BigText variable and then save it to a BLOB field. Something like:

    myTable.BlobField.CREATEOUTSTREAM(outstr);

    varBigText.WRITE(outstr);

    myTable.INSERT;

  • Olister Rumao Profile Picture
    Olister Rumao 3,957 on at
    RE: How to insert DataUri in Text to Blob in NAV 2018 AL

    Let me explain the scenario

    Scenario:

    In NAV 2017 we used a Signature Control Add-in. We created the signature add-in with its core as a canvas which was created using Javascript. The interaction with the Javascript was done with the help of events i.e ClearSignature Event, AcceptSignature Event. These events send the data in the form MemoryStream. In NAV 2018 we've used DataUri to send data via the AcceptSignature Event. As the event which is called from Javascript doesn't allow parameter as a BLOB file in AL.

    Is there a way to convert the DataUri which is greater than 2500 characters be converted to BLOB?

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: How to insert DataUri in Text to Blob in NAV 2018 AL

    What event do you mean? It's quite difficult without seeing the code.

    Another idea could be to save the image as a temporary file and then from AL store it on a BLOB field.

  • Olister Rumao Profile Picture
    Olister Rumao 3,957 on at
    RE: How to insert DataUri in Text to Blob in NAV 2018 AL

    Hi Stefano,

    Tried that as well but there is event trigger from JS to AL which doesnt allow BLOB as its parameter.

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: How to insert DataUri in Text to Blob in NAV 2018 AL

    Text fields on tables have this limit. I think you can also directly save the Canvas as BLOB from JS. There are samples to do so on the net.

  • Olister Rumao Profile Picture
    Olister Rumao 3,957 on at
    RE: How to insert DataUri in Text to Blob in NAV 2018 AL

    Hi Stefano,

    I've converted  canvas to DataUri which is a text but since it exceeds 250 characters, it cannot be stored as text. Is it possible to convert Text having length >2500 to blob in AL??

  • Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: How to insert DataUri in Text to Blob in NAV 2018 AL

    You can store it as a BLOB and convert/deconvert it as needed. Check here:

    [View:https://stackoverflow.com/questions/23150333/html5-javascript-dataurl-to-blob-blob-to-dataurl]

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans