目前喜欢解析似乎无法上传文件以使用 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
有人可以解释一下这种奇怪的情况吗(我相当确定我正在严格遵循文档。
最佳答案
你应该尝试使用 Base 64 编码,它终于可以工作了:
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
});
关于javascript - 创建 Parse.File 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26217781/