parse.com多个文件上传失败

时间:2015-06-19 17:38:18

标签: javascript file parse-platform

我正在尝试使用以下方法将多个文件上传到parse.com数据库:

function uploadPhotos() {
    if ( files != null )
    {
        var count =0;
        for (var i=0;i<fileCnt;i++)
        {

            file = files[i];
            var photoComment = comments[i];
            var parseFile = new Parse.File("photo.jpg", file, "image/jpg");
            parseFile.save().then(function() {
                // The file has been saved to Parse.
                BK_PHOTOS[i] = new Parse.Object("BK_PHOTOS");
                BK_PHOTOS[i].set("bk_comment", photoComment);
                BK_PHOTOS[i].set("bk_photo", parseFile);
                BK_PHOTOS[i].save();
                count++;
                if(count == fileCnt)
                {
                    saveObject();
                }

            }, function(error) {
                // The file either could not be read, or could not be saved to Parse.
                console.log("Error!");
            });

即使files数组包含不同的文件,也会多次上传同一个文件。

1 个答案:

答案 0 :(得分:0)

这对我有用

var imageFiles = document.getElementById(“profilePhotoFileUpload”);       var filesLength = imageFiles.files.length;

  for (var i=0;i< filesLength;i++){

    var file = imageFiles.files[i];
    var name = imageFiles.files[i].name; //This does *NOT* need to be a unique name
    var parseFile = new Parse.File(name, file);
    parseFile.save().then(function() {

      var Pic = new Parse.Object.extend("PICS");
      Pic.set("itemPicture", parseFile);
      Pic.save();

    }, function(error) {

      //error handling

    });