Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

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

Open
qualisign opened this issue Jan 27, 2018 · 0 comments

Comments

@qualisign
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant