lastprogrammer
lastprogrammer

Reputation: 11

POST canvas image from JavaScript to RESTful Web Services

I'm currently implementing a tool whereby it needs to save canvas image from HTML JavaScript and upload the canvas image to RESTful web services using JSON.

I'm stuck at how to upload canvas image using JSON to webservices and how to implement code that retrieve the canvas image to Web services side using Java.

Upvotes: 1

Views: 733

Answers (1)

Adam Popkiewicz
Adam Popkiewicz

Reputation: 105

I did that some time ago with storing thumbnails of canvas rendered picture. Basically canvas object has toDataURL() method, I called it like toDataURL("image/png"), and stored it in hidden field in form, but you could as well send it directly with ajax call.

then basically I kept the image in that format in db, but you can store it on hard drive, probably more sustainable long term. example ruby/rails implementation of thumbnail retrieval:

def thumbnail
  render :status => 200,
         :content_type => 'image/png',
         :text =>  Base64.decode64(
           thumbnail["data:image/png;base64,".length .. thumbnail.length]
         ) # there is extra "data:image/png;base64," at the start
end

Upvotes: 1

Related Questions