ParseFile javascript - 保存为字节

时间:2015-09-24 20:47:46

标签: javascript pdf parse-platform pdf-generation

我尝试使用Parse javascript SDK将PDF文件保存为ParseFile:

HTML

var requestUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/lists/getbytitle('" + listTitle + "')/items?$select=Title";

$.getJSON(requestUrl,function(data){
   //print results
   $.each(data.value,function(i,item){
      console.log(item.Title);  
   }); 
});

JS

<input type="file" id="profilePhotoFileUpload" onchange="selectFile(event)">

我将字节结果改为:

http://files.parsetfss.com/637e62db-7116-473c-97dc-48ad15ce73ca/tfss-f5f522d0-0634-4e98-9f2a-be659e5dac00-asdasdas.pdf

任何解决方案?

1 个答案:

答案 0 :(得分:1)

<强>解决

默认文件数据是Text。 我使用FileReader将数据作为base64,然后我保存这样的数据:

fr = new FileReader();
fr.onload = receivedText;
fr.readAsDataURL(file);

function receivedText() {           
    result = fr.result;
    var res = result.split("base64,");
    var name = "myFile.pdf";
    var parseFile = new Parse.File(name, { base64: res[1] });
    parseFile.save().then(function() {
        console.log("object saved!");
    }, function(error) {
      // The file either could not be read, or could not be saved to Parse.
    });
}