如何上传使用Parse.com javascriptSDK的图像?(How do I upload

2019-06-27 19:51发布

我使用Parse.com建立一个JavaScript应用程序,我需要上传的照片。 我有一个形式,它允许用户选择自己的文件系统中的图像,但我该怎么做旁边用它? 我找不到解析网站(不适用于javascriptSDK,反正)这方面的任何文件。

谢谢你的帮助!

Answer 1:

下面是关于如何上传的图像一个简单的例子:

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.15.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

  // ***************************************************
  // NOTE: Replace the following your own keys
  // ***************************************************

  Parse.initialize("YOUR_APPLICATION_ID", "YOUR_CLIENT_ID");

  function saveJobApp(objParseFile)
  {
     var jobApplication = new Parse.Object("JobApplication");
     jobApplication.set("applicantName", "Joe Smith");
     jobApplication.set("profileImg", objParseFile);
     jobApplication.save(null, 
     {
        success: function(gameScore) {
          // Execute any logic that should take place after the object is saved.
          var photo = gameScore.get("profileImg");
          $("#profileImg")[0].src = photo.url();
        },
        error: function(gameScore, error) {
          // Execute any logic that should take place if the save fails.
          // error is a Parse.Error with an error code and description.
          alert('Failed to create new object, with error code: ' + error.description);
        }
     });
  }

  $('#profilePhotoFileUpload').bind("change", function(e) {
         var fileUploadControl = $("#profilePhotoFileUpload")[0];
         var file = fileUploadControl.files[0];
         var name = file.name; //This does *NOT* need to be a unique name
         var parseFile = new Parse.File(name, file);

         parseFile.save().then
         (
           function() 
           {
               saveJobApp(parseFile);
           }, 
           function(error) 
           {
             alert("error");
           }
         );
  }); 

});
</script>

<body>
    <input type="file" id="profilePhotoFileUpload">
    <img id="profileImg"/>
</body>


Answer 2:

好吧,我发现了一些更谷歌搜索后的答案(后它发生,我对谷歌“文件上传”,而不只是“图片上传”!)。 我用这个:

http://help.gotiggr.com/documentation/services/examples-connecting-to-mobile-back-ends/parse/file-upload

认为它可能派上用场了别人!



文章来源: How do I upload an image using the Parse.com javascriptSDK?