Question
· Jan 14, 2021

Saving image data from csp

I created a csp that will capture image data from a html canvas element.  I created a button element to save the contents as a dataURL string from jpeg and make a server call.

the string is too long

I would appreciate any suggestions in saving the data into the server, currently just a global.

Discussion (2)0
Log in or sign up to continue

The best way of doing this is to create a class with a single property 'property Data as %BinaryStream'

class MyData extends %Persistent

{

property Data as %BinaryStream;

}

Then, I assume you you have a class that inherits from %CSP.REST (assume it is called MyRestClass) and in the XDATA Routes block define a route definition

<Route Url="/myapp" Method="POST" Call="SaveData" />

where /myapp is a Web Application defined in Management Portal -> System Administration -> Security -> Applications -> Web Applications. When you define the application specify the application URL ("/myapp"), the namespace where your data is going to be saved, and in the field "Dispatch Class" specify  "MyRestClass" and then Save the Web Application Definition.

in your REST Class(MyRestClass) define a class method

classmethod SaveData() as %Status

{

    set tSC=$$$OK

    try {

        set obj=##class(MyData).%New()

        set tSC=obj.Data.CopyFrom(%request.Content) if 'tSC quit

        set tSC=obj.%Save() if 'tSC quit

    }

    catch ex {set tSC=ex.AsStatus()} 

    quit tSC

}

This is just one approach. As Robert suggests below there are a number of ways of manipulation images in CSP but my example is one that I have used before