This is a migrated thread and some comments may be shown as answers.

Object Data Type

2 Answers 126 Views
JavaScript SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris GNB
Top achievements
Rank 1
Chris GNB asked on 23 Jul 2014, 12:21 PM
Hi,
Im using the backend services / kendoui and Im trying to save a signature captured using jSignature.js. The capture appears well on screen in the list view but i cant work out how when i save to get the signature data into the backend service. 
Everything else on the form is saved without issue.
If anyone has any ideas on how this can be achieved i would be very grateful.

Thanks Chris

2 Answers, 1 is accepted

Sort by
0
Accepted
Anton Dobrev
Telerik team
answered on 24 Jul 2014, 10:56 AM
Hi Chris,

You can choose between two options for saving the signature in Telerik Backend Services:
  • Save the created signature as a picture.
  • Save the created signature as a base64 string.

Which one to choose may depend on the jSignature library's import/export specifics and the scenario of your app.

1. Upload the exported signature to the system "Files" installment.
var $sigdiv = $("#signature");
var datapair = $sigdiv.jSignature("getData", "svgbase64");
 
var file = {
    "Filename": "myfile.svg",
    "ContentType": "image/svg+xml",
    "base64": datapair[1]
};
 
var el = new Everlive("MyApiKeyHere");
 
el.Files.create(file,
    function(data) {
        console.log(JSON.stringify(data.result.Uri));
    },
    function(error) {
        alert(JSON.stringify(error));
    });

You will receive the URL of the image in the data.result.URI field.

2. You can create a dedicated content type and save the created signatures as a JSON object:
var $sigdiv = $("#signature");
var datapair = $sigdiv.jSignature("getData", "svgbase64")
 
var obj = {
    "datatype": datapair[0], // backend type "Text"
    "content": datapair[1], // backend type "Text" or "Object"
    "signatureName": "MySignature"
};
 
var el = new Everlive("MyApyKeyHere");
 
var data = el.data('MySignatures');
data.create(obj,
    function(data) {
        console.log(JSON.stringify(data.result.Id));
    },
    function(error) {
        alert(JSON.stringify(error));
    });

You can retrieve an item by using the following snippet:
data.getById('IdOfTheItemHere',
    function(data) {
        var i = new Image()
        i.src = "data:" + data.result.datatype + "," + data.result.content;
        $(i).appendTo($("#signature-container"));
    },
    function(error) {
        alert(JSON.stringify(error));
    });

I hope that this helps. Please, let us know if you have further questions.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Chris GNB
Top achievements
Rank 1
answered on 25 Jul 2014, 08:28 AM
Thanks that worked a dream.
Tags
JavaScript SDK
Asked by
Chris GNB
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Chris GNB
Top achievements
Rank 1
Share this question
or