How do you access the Data URI as a string from within Processing.js?

edited August 2014 in JavaScript Mode

Hello all,

I am making a webapp/applet and I created my Processing program already. I intend on implementing this program into my HTML and posting from my hosting account. I got everything up and running except one thing... I cannot access the images that the save() action creates. I found out that if it's integrated in HTML then the save() action creates a Data URI out of the image instead of saving an actual image to the local drive. That's fine with me because I can already load Data URIs into my HTML... But how do you GET the Data URI string from within Processing???

My program saves images when mousePressed. I want to archive and post them on the same site. So, I need to have access of the Data URI string that's in the address field that pops up in the new window.

I found out that Processing.js save() is what makes this new window pop up happen, but how do I gain access to a Data URI and assign it to a String within Processing?...

Wut2do?

Answers

  • Answer ✓

    save() just takes a PGraphics and saves it, or,here, converts it to a data URI.
    So, if you want to reuse this image, just copy it (with copy(), get() or similar), instead of using save() which, apparently, in JS, just isolates an image to allow the users to download it on their computer (JS doesn't allow to save a file directly for security reasons).

  • edited August 2014 Answer ✓

    Hmmm... I see.

    This could work if I made the archive section part of the same Processing app.

    Cool, thank you, PhiLho!

    Actually I found a snippet that saves to the server:
    wiki.processing.org/w/Saving_files_to_a_web_server
    It works with the save() function and I got it to work.

    For people wanting to try this, I did a few things:

    1. I changed the url in the Processing snippet:
      "http://yourdomainname.com/uploadMe.php"

    2. I made a folder in my server root called uploads.

    3. I used the sudo chown method, and this should only work with an Apache server:
      I changed: $uploaddir = '/var/www/uploads/';
      to: $uploaddir = 'uploads/sudo chown -R www-data:www-data uploads';

    4. I saved the php snippet to uploadMe.php and uploaded it to my server root. I saved the php file to something different than index.php because in my hosting account there was an index.php file already. Note: You can name the .php file what you want, just make sure you put that name at the end of the path of the Processing snippet too as stated above.

    Good luck... and may the Mole People have mercy on yer soul.

  • Cool if you can use PHP on your server. Most people here are stopped as soon as we talk about PHP or other server side code...

  • edited August 2014

    Indeed for JS, the server is its "OS"! ;;)
    In regular "offline" programing languages like Java, all OS's resources are available!
    But for an "online" language like JS, it's gotta ask the server via another back-end language
    such as PHP, for any external resources!
    I've also heard that Node.JS is a good option over PHP! O:-)

Sign In or Register to comment.