Home Ask Login Register

Developers Planet

Your answer is one click away!

Marc Zaharescu February 2016

Chrome Extension - Upload CSV File to Dropbox Format Issue

I am building a chrome-extension that is required to upload a CSV file to dropbox.

Everything works fine apart of the way the data is structured inside the file that has been successfully uploaded to dropbox.

I am also downloading a local copy of the file and everything looks fine for it, but on dropbox it doesn't seem to recognize the endline characters ("/r/n"), and it translates the white spaces as "%20". Here is a part of my code where I create the file and upload it to dropbox:

function downloadCSV()


// create a csv file with the table data using base64
var encodedUri = encodeURI(localStorage.Table);
var file = 'data:Application/octet-stream,' + encodedUri;
var date = new Date();
// filename contains the unique user id + a timestamp of the current date with year, month, day, hours, minutes, seconds
var filename=uniqueID +"  "+date.getYear()+ "-" +date.getMonth() +"-" +date.getDate() +": " +date.getHours() + "." +date.getMinutes() +": "+date.getSeconds()+".csv";

var link = document.createElement("a");
link.setAttribute("href", file);
link.setAttribute("download", filename);

//create a xmlhttp request to send a post request to box.com using the authenthification token
var uploadUrl = 'https://api-content.dropbox.com/1/files_put/dropbox/myfolder/'+filename;

// The Box OAuth 2 Header. Add your access token.
var headers = {
    Authorization: 'Bearer '+localStorage.authorization_token

    url: uploadUrl,
    headers: headers,
    type: 'PUT',
    // This prevents JQuery from trying to append the form as a querystring
    processData: false,
    contentType: false,
    data: link
}).complete(function ( data ) {
    // Log the JSON response to prove this worked

// resets the Table variable


I tried to encoded in


nAviD February 2016

Try using contentType:'application/octet-stream'

smarx February 2016

I don't understand what you're trying to do in your code. It looks like you're creating a hyperlink with a URL-encoded version of your data as the href, but then you're passing that link variable as the data to an AJAX request... what does that end up doing? You should just pass the data:

    data: /* the actual data you want to upload here */

I can't tell from your code if localStorage.Table is the actual CSV data or not. (A comment mentions base64 encoding?) But whatever variable holds the exact CSV data you want in the file should be passed as the data parameter on your HTTP request. Don't base64-encode, don't URL encode, etc.

Post Status

Asked in February 2016
Viewed 3,706 times
Voted 9
Answered 2 times


Leave an answer

Quote of the day: live life