nano icon indicating copy to clipboard operation
nano copied to clipboard

uploaded files displaying base64 data in the browser (attachments not viewable)

Open qualisign opened this issue 8 years ago • 0 comments

I'm using couchdb to store attachments that I need to display in the browser.

The data is uploaded from an html input and then processed when saveDoc is called:

getFileData: function(file){
    var reader = new FileReader();
    return new Promise(function(accept, reject){
        reader.onload = (e) => {
            accept(e.target.result)
        };
        reader.readAsDataURL(file);
    })
},
saveDoc: function(name, type, filedata, url){
    console.log(filedata)
    var self=this
    return new Promise(function(accept, reject){
        self.getData(url).then(data => {
            var rev = data['_rev']
            console.log(url + ' is the url')
            console.log(name + ' is the filename')
            documentation.attachment.insert(url, name, filedata, type,
                                            { rev: rev }, function(err, body) {

                                                if (!err){
                                                    console.log(body);
                                                }
                                                else {
                                                    console.log(err)
                                                }
                                            })
        }).catch(err => {
            console.log(err)
        })
    })
},

I don't get any errors while uploading from the console. But when I navigate to where the attachment should be in the console, I see a browser message telling me the data can't be displayed (for pdf/images), or I see a base64 string that looks like this:

data:image/png;base64,iVBOR...

when the attachment is an html document.

(The data being logged on saveDoc looks like this: data:application/pdf;base64,JVBER...)

The correct content type as well as a reasonable length is being displayed in my couchdb admin with metadata on the files, so there are no obvious header problems. Can anyone think of any other reason this might not be working in the browser?

qualisign avatar Jan 27 '18 10:01 qualisign