2014-01-26 181 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); 
相關問題