Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

http GET and PUT binary data (CouchDB attachments) from javascript

I need to download, edit and upload (via HTTP PUT) binary blobs to CouchDB (as attachments) from a browser javascript CouchApp.

My google-fu fails me to find anything even remotely similar to this :/

Current solution involves using Silverlight, and I wish to go plain-js on modern browsers (Safari, Mobile Safari (iOS), IE 9, Opera 11 etc)

There is a solution for uploading data in Chrome ( Post binary data cross domain in javascript ) , but I don't want to stick to that particular browser.

like image 447
wizzard0 Avatar asked Oct 10 '22 00:10

wizzard0


1 Answers

Javascript is a bit inconvenient for dealing with binary data, but it should still be possible.

The simplest way to do this is to use CouchDB's base64 version of the attachments. You can get attachments inline in a document, and then store them back as inline attachments.

You can use any Javascript base64 library to decode them in the browser. CouchDB includes one as part of its Futon application. You can retrieve it from /_utils/script/base64.js.

like image 92
JasonSmith Avatar answered Oct 13 '22 09:10

JasonSmith