2014-01-26 133 views
1

我有注册表单,在那里我想让用户上传他的图像​​。上传图像到parse.com并将其保存在数据库中

这是我尝试上传到parse.com的JS: 我得到警报的代码100(有因为正规注册工作的良好connectin parse.com没问题)

var fileUploadControl = $("#img1")[0]; 
if (fileUploadControl.files.length > 0) { 
    var file = fileUploadControl.files[0]; 
    var name = "photo.png"; 

    var parseFile = new Parse.File(name, file); 

    parseFile.save().then(function() { 
    // The file has been saved to Parse. 
    var url = parseFile.url(); 


    user.set("img", url); 


}, function(error) { 
     alert("Error: " + error.code + " " + error.message); 

    // The file either could not be read, or could not be saved to Parse. 
}); 
} 

这是在html,其中 “IMG1” 申报

<form dir="rtl" class="form-container" id="signUp_form" method='post'> 
......................... 
...................... 
<input type="file" name="img1" size="40" id="img1" onchange="readURL(this);"> 
<img id="blah" src="empty-f.gif" alt="your image" width="150px" height="150px" /> 
</form> 

,如果是相关的:

function readURL(input) { 

     if (input.files && input.files[0]) { 
      var reader = new FileReader(); 

      reader.onload = function (e) { 

       $('#blah') 
        .attr('src', e.target.result); 
      }; 

      reader.readAsDataURL(input.files[0]); 
     } 
    } 

谢谢

回答

0

如果用户img列是一个指向图像对象的指针,则需要将值设置为图像对象而不是url。

user.set("img", parseFile); 
相关问题