Does any one implemented uploading pdf to dropbox, I am using dropbox api and file plugin.
I tried every method of file plugin (ReadAsArrayBuffer
, ReadAsBinaryString
, ReadAsText
) using all that I am able to upload file to dropbox however format of PDF got corrupted upon downloading.
Please let me know if anybody has any solutions on it
function readDataUrl(file) {
var reader= new FileReader({'blob': true});
alert('in readDataUrl');
console.log("file is",JSON.stringify(file));
// var reader = new FileReader();
reader.onload = function(evt) {
alert("reading completed");
// console.log("Read as data URL");
// console.log(new Uint8Array(evt.target.result));
// Now upload this file to dropbox
data = evt.target.result;
// data = evt.target.result.match(/,(.*)$/)[1]
uploadToDrpBox(data);
}
reader.readAsDataURL(file)
}
function uploadToDrpBox (data){
alert('in upload');
// console.log(data);
var deferred = $q.defer();
$cordovaOauth.dropbox("App_ID").then(function(result){
alert('in auth',result);
// console.log(result);
acc_token = result.access_token;
$http.put('https://api-content.dropbox.com/1/files_put/auto/'+$scope.docName+".pdf",data,{headers:{'Authorization' : 'Bearer ' +acc_token,'Conent-Length':'undefined','mimeType':'application/pdf','fileKey':"file"}}).then(function(res){
alert("in response");
// console.log(JSON.stringify(res));
deferred.resolve(res);
}, function(error){
alert(JSON.stringify(error));
});
return deferred.promise;
console.log("uploaded file");
});