将图像上传到parse.com并将其保存在数据库中

问题描述 投票:1回答:1

我有注册表格,我想让用户上传他的图像​​。

这是我尝试上传到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.
});
}

这是“ img1”声明的html

<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]);
        }
    }

谢谢

javascript file parse-platform
1个回答
0
投票

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

user.set("img", parseFile);
© www.soinside.com 2019 - 2024. All rights reserved.