创建Parse.File对象

时间:2014-10-06 13:51:58

标签: javascript file-upload parse-platform

此刻的爱解析似乎无法使用javascript api(客户端)上传文件进行解析,问题是我似乎无法创建解析对象。以下是我的代码:

var fileUploadControl = $("#imgInp")[0];
var file = fileUploadControl.files[0];
var name = "photo.jpg";
var parseFile = new Parse.File(name, file);

parseFile.save().then(function() {
// etc

我从Chrome控制台获取的错误是

TypeError: undefined is not a function
at k.$scope.submitReport
(file:///Users/xxx/Documents/projects/script.js:402:27) <- the line which has  var parseFile = new Parse.File(name, file); on it

有没有人可以对这种奇怪的情况有所了解(我相当肯定我是在跟着这封信的文件。

https://parse.com/docs/js_guide#files-classes

1 个答案:

答案 0 :(得分:0)

你应该在base 64中尝试使用编码,它最终会起作用:

&#13;
&#13;
  var fileUploadControl = $("#imgInp")[0];
  var file = fileUploadControl.files[0];
  var uploadFile = new Promise(function(resolve, reject){
        
        var newFile = new Parse.File(String(file.name),{base64:file.image});
        newFile.save();
    
        resolve(newFile)
       
  })
                              
                              
     uploadFile.then(function(){
      
                var results = Array.prototype.slice.call(arguments);             
                 //results === your filesUpload
               });
         
&#13;
&#13;
&#13;