Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending binary data to (Rails) RESTful endpoint via JSON/XML?

I am currently putting together a rails-based web application which will only serve and receive data via json and xml. However, some requirements contain the ability to upload binary data (images).

Now to my understanding JSON is not entirely meant for that... but how do you in general tackle the problem of receiving binary files/data over those two entrypoints to your application?

like image 564
Jörg Battermann Avatar asked Jan 09 '09 01:01

Jörg Battermann


2 Answers

I suggest encoding the binary data in something like base64. This would make it safe to use in XML or JSON format.

http://en.wikipedia.org/wiki/Base64

like image 190
unknownuser Avatar answered Oct 24 '22 11:10

unknownuser


maybe you could have a look on Base64 algorithm. This is used to "transform" everything to ascii char. You can code and decode it. It's used for webservices, or even on dotnet Serialization.

Hope this helps a little.

Edit: I saw "new post", while posting, someone was faster.Rails base64

like image 5
Aif Avatar answered Oct 24 '22 11:10

Aif