将[object file]文件上传到Parse并在查询时获取[object Object]

时间:2015-09-26 07:00:19

标签: javascript html parse-platform

我正在尝试上传图片文件进行解析,但我很丢失。我觉得很失败......叹气......无论如何,我试图修改这个网站上的代码:http://blog.teamtreehouse.com/reading-files-using-the-html5-filereader-api,以便将我的文件上传到Parse。

这是我的HTML:

<div>
    <form id="pictureUploadForm">
        Select an image file: 
        <input type="file" id="fileInput">
        <input type="submit" id="pictureButton"  value="Submit" />
    </form>
</div>

要将我的图像文件上传到Parse,我写了这个(它有效,顺便说一句):

var PictureUploads = Parse.Object.extend("PictureUploads");
var pictureUploads = new PictureUploads();

window.onload = function() {
    var fileInput = document.getElementById('fileInput');

    fileInput.addEventListener('change', function(e) {
        var file = fileInput.files[0];
        alert(file);
        var PictureUploads = Parse.Object.extend("PictureUploads");
        var pictureUploads = new PictureUploads();

        pictureUploads.set("pictureFile", file);

        pictureUploads.save(null, {
            success: function(pictureUploads) {

        },
            error: function(pictureUploads, error) {
            print("didn't work");
            }
        });
    });
}

现在,如果您发现alert(file),它会提醒[object File]。为了检索它,我写了这个(这也有效):

$(document).ready(function(){

    var query = new Parse.Query(PictureUploads);

    query.get("yAIyFJPvFj", {
        success: function(pictureUploads) {
            var file = pictureUploads.get("pictureFile");
            alert(file);
        },
        error: function(object, error) {
            alert("didn't work but don't get mad"); 
        }
    });
});

但问题是,当我通过var file = pictureUploads.get("pictureFile");alert() file检索通过Parse保存为对象的文件时,我得到[object Object]。但我无法使用[object Object],因为我试图在树屋网站上运行其余的代码,但它没有用。

所以,当我查询时,我的问题是,为什么它会返回[object Object],并且有可能以某种方式修改[object Object],使其成为[object File]。请。帮助我......我快死了......

0 个答案:

没有答案