Converting signature pad signature from json to image in server - postgresql

.NET 6 MVC application uses Signature Pad from
https://github.com/szimek/signature_pad to create signatures.
Signature json strings from it are stored in PostgreSql database as strings like
[{"penColor":"blue","dotSize":0,"minWidth":0.5,"maxWidth":2,
"velocityFilterWeight":0.7,"points":[{"time":1664603146607,"x":87.11111450195312,"y":46.8194580078125,"pressure":0.5},
{"time":1664603146948,"x":92.44445037841797,"y":45.9305419921875,"pressure":0.5},
{"time":1664603146981,"x":100.44444274902344,"y":50.375,"pressure":0.5},
{"time":1664603147051,"x":105.77778625488281,"y":52.152801513671875,"pressure":0.5}]}]
How to convert this json to image data url in server side?
Github contains only javascript code for conversion in client side.
How to implement this in server? Should javascript converted to C# (no idea how to render canvas in C#), can this javascript run? Application also uses SixLabors.ImageSharp, maybe this can used.

Related

How to configure swagger_dart_code_generator to replace the DateTIme.parse generated?

I am working on a Flutter App that gets data from a WCF Service which returns JSON format.
App diagram
I got the swagger specification and used swagger_dart_code_generator to generate the Client API.
When I tested the Dart Client API, a FormatException arises as shown below.
Date Time Format Exception
This error arises in the code generated by swagger_dart_code_generator, is there a way to replace DateTime.parse(json['...']) by my custom JSON converter WcfDateTime.fromJson(..) for all DateTime types ?

Issue with decoding base64 encoded app engine data in swift

I am developing ios app which is getting data from Google endpoint ,the data is base 64 encoded on the server to a custom java object, which is then returned by the endpoint method.
On the iOS side I am able to receive the data and print the data using the generated client code.
I am facing a problem and I am unable to decode the data back in to the GTL**** endpoint auto generated class.
The decoded data shows up with some hex numbers:
My Code:
let respo2 = GTLDecodeBase64(responce) as? GTLEndpointStatusCollection
I also tried decoding using the swift classes:
let respo = NSData(base64EncodedString: responce, options: NSDataBase64DecodingOptions(rawValue: 0))
The input is base64 encoded : rO0ABXNyABNqYXZhLnV0aWwuQXJyYXlMaXN0eIHSHZnHYZ......
The desired output should have been readable data,
but instead im getting:
<aced0005 73720013 6a617661 2e757469 6c2e4172 7261794c.....
I even tried encoding, decoding the base64 decoded data with NSUTF8
but no use.
What am I doing wrong? Is it possible for data encoded on Server in Java (with custom Java objects) to be decoded back ? (I understand Google endpoint does the serialization/deserialization in between)
Thanks in advance.
You should use JSON for serialization rather than manually converting the object to a bytestring and base64 encoding it. If you are using the Endpoints libraries this is automatically done for you, simply by returning the object in your method. See the docs here for an example and the rest of the Endpoints docs for more details. To consume the API you can use the generated iOS libraries which also do this for you as per the examples here. You won't actually see any JSON unless you inspect the HTTP traffic or use the API Explorer.
It sounds like you might just be doing more work than is needed by pre-encoding the object, rather than just letting Endpoints do it for you. If you really need to manually serialize an object to some property you can use a library on the Endpoints side like Jackson to serialize the object to a string property and NSJSONSerialization on the client to convert it back to an object.

MTOM and WS-Security (in CXF)

I am using WS-Security (XML-Signature and XML-Encryption) in my Web Service. For larger, binary objects, I intend to use MTOM.
From what I understood is that the binary data is referenced via something like this:
<xop:include href="SomeUniqueID"/>
I see two problems here:
1) How can I include this binary data in the XML-Signature part of the SOAP header?
2) How can I use XML-Encryption (or to be more specific: CXFs standard ways of "automatically" doing XML-Encryption)?
You can include the data in the XML-Signature as if you were not using MTOM.
When MTOM is enabled, at first, the data will always be encoded in Base64 and then it will be converted to binary data to send it as a MIME attachment.
CXF will use this temporary Base64 representation of your file to include it in the message signature.

How to convert all \u**** string into the real readable NSString? [duplicate]

I am trying to support arbitrary unicode from a variety of international users. They have already put a bunch of data into sqlite databases on their iPhones, and now I want to capture the data into a database, then send it back to their device. Right now I am using a php page that is sending data back to from an internet mysql database. The data is saved in the mysql database properly, but when it's sent back it comes out as unicode text, such as
Frank\u00e2\u0080\u0099s iPad
instead of just
Frank's iPad
where the apostrophe should really be a curly apostrophe.
The answer posted to another question indicates that there is no built-in Cocoa methods to convert the "\u00e2\u0080\u0099" portion of the unicode string from the webserver to an NSString object. Is this correct?
That seems really surprising (and scarily disappointing), since Cocoa definitely allows input from many different Unicode characters, and I need to support any arbitrary language that I have never heard of, and all of the possible characters. I save them to and from the local sqlite database just fine now, but once I send it to a web server, then perhaps pull down different data, I want to ensure the data pulled from the web server is correctly formatted.
[...] there is no built-in Cocoa methods to convert [...]. Is this
correct?
It's not correct.
You might be interested in CFStringTransform and it's capabilities. It is a full blown ICU transformation engine, which can (also) perform your requested transformation.
See Using Objective C/Cocoa to unescape unicode characters, ie \u1234
All NSStrings are Unicode.
The problem with the “Frank\u00e2\u0080\u0099s iPad” data isn't that it's Unicode; it's that it's escaped to ASCII. “Frank’s iPad” is valid Unicode in any UTF, and is what you need.
So, you need to see whether the database is returning the data escaped or the PHP layer is escaping it at some point. If either of those is the case, fix it if you can; the PHP resource should return UTF-8/16/32. Only if that approach fails should you seek to unescape the string on the Cocoa side.
You're correct that there is no built-in way to unescape the string in Cocoa. If you get to that point, see if you can find some open-source code to do it; if not, you'll need to do it yourself, probably using NSScanner.
Check that your web service response has Content type and charset. Also that xml has encoding specified. In PHP you need to add the following before printing XML:
header('Content-type: text/xml; charset=UTF-8');
print '<?xml version="1.0" encoding="UTF-8"?>';
I guess there is just no encoding specified.

XML data text + binary

I built an iPhone app that is getting information from a server (this is also a server that I built).
The data from the server is XML and I use the XML parser to parse the message.
What I want is to add an image to be sent from the server, and I am asking if I can add binary data of such an image to the XML message. For example 10 tags will be text and 1 tag will be binary (the image). So when the XML parser gets to the binary tag, it inserts the data to NSDATA object and the rest of the tags will be inserted to NSString.
Does the XML parser of Cocoa can handle this situation?
If not, what do you think will be the easiest way to do this with one connection to the server so that the data from the server is sent once.
To transfer binary data wrapped in XML, encode it using e.g. Base64, which turns your binary data into characters that won't mess up your XML.
You can transfer the image data, encoded using Base64. There is this NSData category by Matt Gallagher that adds Base64 decoding support to NSData (dateFromBase64String). You can find it on his Cocoa with love website.
Mind you that encoding images in Base64 adds about 33% in file size.