I am a newbie using webgl implementation as a dependent module for my project. I am trying to use .toDataURL() function using node-webgl wrapper at server side. But I get an error station .toDataURL() is undefined. For more detail, please have a look at this link: canvas.toDataURL() is not a function - error node-webGL wrapper
Well the current post is definitely not a duplicate. In the post(earlier link shared) I am trying to find an alternative way to access the data of canvas. The goal of this current post is to implement the .toDataURL() function. I am novice in these webgl. Could you please share some links or procedure on how to implement this small function. or Could I access the same function of browser implementation(copy it here), where can I get that?
Any suggestions will definitely be helpful.
Thank You.
A data URI consists of:
data:[<media type>][;base64],<data>
All you need to do is concatenate:
a string "data:"
a media type - e.g. "image/jpeg"
a string ";base64,"
Base64 representation of your data
For more info see:
https://en.wikipedia.org/wiki/Data_URI_scheme
https://en.wikipedia.org/wiki/Base64
There are several modules on npm that can help you generate Base64:
https://www.npmjs.com/search?q=base64
This is basically everything that you need to know to implement toDataURL() function.
Related
I'm working on an MVP for a project, and I'm trying to mock up a "database" quick and dirty. I thought for now I'll just put my "database" into a .json file and work with that. I am able to use iron-ajax to get a file read in to a Polymer property to be manipulated, however, I don't know how I could write it back onto the filesystem once I manipulated it. I tried
let fs = require('fs');
fs.writeFile('./db/db.json', json, 'utf8');
However, this does not work (apparently, require does not work on the client side). I've tried googling around and checking the answers on the linked thread, but the answers are quite vague ("use <script> tag" - okay, but how?) and I haven't been able to figure it out. How would I be able to pass a json object and write it back to the filesystem?
Simple answer is no you can't. You have to write a little backend for that but for that i usually use the localStorage there you can store JSON and read write.
Forgive the lack of code but I'm working in a production environment and it's a lot. I can provide more specific examples if needed but I will explain the basic situation here.
I'm using a library called PdfMake (which is excellent btw, great for making pdf's in JS if you need that) to make a dynamic PDF on the fly.
Now I need to get the PDF into an S3 bucket, but our stack currently relies on ColdFusion. Luckily, PdfMake has a handy method to convert the pdf data to Base64 and ColdFusion has a handy function to convert Base64 to binary.
So I sent the base64 to my server, convert it to binary, make a new coldfusion pdf and read it like this (fileData is a base64 encoded string)
public function upload_pdf(string fileName, any fileData){
var myPdf = new pdf();
var binary = ToBinary(arguments.fileData);
myPdf.read( source=binary, name="fileSource");
}
For some reason this action is failing. I usually get an error that says "The Document has no catalog of type dictionary", which is very cryptic and brings up no helpful results when I search it. Sometimes, without changing anything, I get an error that reads "the rebuild document still has no trailer". From googling it seems trailers are something specific to do with PDFs.
Intuitively I would think that this would work, since base64 and binary are versatile types of encoding. However I'm at a loss as to how to even begin to fix or diagnose this. I will probably begin looking for another solution altogether but I am curious to learn more about what is happening here so if anyone has any ideas I am down for some discussion.
FOR ANY CURIOUS READERS I HAVE SOLVED THIS PROBLEM, HERE IS THE WORKING CODE:
public function upload_pdf(string fileName, string fileData){
var myPdf = new pdf();
var binary = decodeBinary(Replace(arguments.fileData, " ", "+", "ALL"));
myPdf.setSource(binary);
}
I am trying to grab a URL on a page via a Chrome Extension. I then need to read this file as binary data before posting it to an external API. I'm wondering how to accomplish this, and if it is even possible. The file type would be PDF, Word Doc or text file typically. We are working with Resumes'.
I have starting reading about File objects and the FileReader, but my initial tests have returned no luck. Anyone have any examples that I could use as a starting off point?
If you could point me in the right direction I would appreciate it.
You definitely can do this. A FileReader should have the method readAsArrayBuffer, which will give you an ArrayBuffer, which you can then inspect by creating a Uint8Array or a DataView on which you can call methods like getUint32, etc.
you might want to take a look at jBinary
I am developping a client side application with HTML5
my datas (only text data) are stored in my file JSON (70 Mega).
I want to implement a function to search all occurences in my data file.
Does exists open source of this function? or what is the best way to implement it?
thanks for your opinions
If you are planning to use Javascript on the client side, take a look at http://kiro.me/projects/fuse.html
However,70Mb of data is simply too much for any browser to handle and a client side search implementation is definitely not recommended.
I'm work on a project recently, which need to pass a binary-stream from npapi plugin to javascript, I've tried following ways:
use NPN_InvokeDefault, i created a string variant which store the binary-stream, and invoke it to javascript, it failed. (i've tried to pass binary-stream read from XXX.txt file, it works!)
i tried to use NPN_NewStream, the example listed in http://www.terraluna.org/dgp/cvsweb/PluginSDK/Documentation/pi3.htm#npnnewstream workes, but the pic is loaded in a new browser tab, i don't know how to recieve it in javascript.
Is there any one have ever met similar problem before? or maybe npapi can't support such kind of data transfering?
looking forward to your suggestiongs, thanks a lot.
Unfortunately, NPAPI was never designed with this purpose in mind. There are a couple of ways you can do it, and none of them are really ideal:
You can create a javascript array and pass the data in small 1-4 byte chunks (this is really very inefficient)
You could create a webserver embedded in the plugin and request the data from there (I have done this and it can work quite well, but keep in mind that if you use this from an SSL website you'll get security warnings when the embedded webserver isn't SSL)
You can base64 encode the binary data and send it as a string.
Those are the ways I have seen it done. The reason you can't send the actual binary data directly as a string is that NPAPI requires string data to be UTF8, but if you base64 encode it then it works fine.
Sorry I can't give you a "happier" solution :-/