couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carl Douglas <carl.doug...@gmail.com>
Subject Changing an attachment content-type through Futons source editor.
Date Tue, 03 Nov 2009 04:44:17 GMT
Hi,

Not sure if this is a bug, a feature or documentation request.

I am using XMLHttpRequest to PUT an attachment to an existing
document. This works, see my client side JavaScript below.

However I noticed sometimes someone uploads an attachment but Firefox
got the content-type wrong (done on the client side with my SUPER
HACK).  To correct this, I use Futon to edit the document JSON source
and change the content_type and save the document. But my change to
the content_type field does not get saved.

I guess I can take a look at the Futon source, but thought I'd ask
here first for suggestions.

Carl

<script type="text/javascript">
 $(function() {
   $('#upload-form').submit(function(){
     // Have to ask for the doc JSON in order to get the rev
     // since we can't PUT or DELETE attachments without the current rev.
     // Not having the current rev, results in 409 conflict.
     $.getJSON("<%= docURL %>", function(doc){
       // Firefox 3 only...
       var file = $('#upload-form #file')[0].files.item(0);
       var xhr = new XMLHttpRequest();

       xhr.open("PUT", "<%= docURL %>/" + file.fileName + "?rev=" +
doc._rev, true);
       xhr.onreadystatechange = function() {
         if (xhr.readyState == 4) {
           if (xhr.status == 201) {
             // OK!
            } else {

            }
         }
       };
       xhr.setRequestHeader('Content-Length', file.fileSize);
       // Mime-type SUPER HACK
       xhr.setRequestHeader("Content-Type",
file.getAsDataURL().match(/data:([^;]*);/)[1]);
       xhr.sendAsBinary(file.getAsBinary());
     });
     return false;
   });
 });
</script>

Mime
View raw message