javascript - Chrome Extension - Upload CSV File to Dropbox Format Issue -


i building chrome-extension required upload csv file dropbox.

everything works fine apart of way data structured inside file has been uploaded dropbox.

i downloading local copy of file , looks fine it, on dropbox doesn't seem recognize endline characters ("/r/n"), , translates white spaces "%20". here part of code create file , upload dropbox:

function downloadcsv() {  localstorage["timestamp"]="inactive"; localstorage["profileviews"]="";  // create csv file table data using base64 var encodeduri = encodeuri(localstorage.table); var file = 'data:application/octet-stream,' + encodeduri; var date = new date(); // filename contains unique user id + timestamp of current date 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); link.click();  //create xmlhttp request send post request box.com using authenthification token var uploadurl = 'https://api-content.dropbox.com/1/files_put/dropbox/myfolder/'+filename;  // box oauth 2 header. add access token. var headers = {     authorization: 'bearer '+localstorage.authorization_token };   $.ajax({     url: uploadurl,     headers: headers,     type: 'put',     // prevents jquery trying append form querystring     processdata: false,     contenttype: false,     data: link }).complete(function ( data ) {     // log json response prove worked     console.log(data.responsetext); });     // resets table variable  localstorage["table"]="";   } 

i tried encoded in every possible way result still same. assistance in solving appreciated.

i don't understand you're trying in code. looks you're creating hyperlink url-encoded version of data href, you're passing link variable data ajax request... end doing? should pass data:

$.ajax({     ...     data: /* actual data want upload here */     ... }); 

i can't tell code if localstorage.table actual csv data or not. (a comment mentions base64 encoding?) whatever variable holds exact csv data want in file should passed data parameter on http request. don't base64-encode, don't url encode, etc.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -