2012-09-05 3 views
3

저는 Parse.com을 사용하여 자바 스크립트 앱을 제작하고 있으며 사진을 업로드해야합니다. 사용자가 파일 시스템에서 이미지를 선택할 수있게 해주는 양식이 있지만 그 다음에 무엇을 할 수 있습니까? 나는 이것에 대한 어떠한 문서도 Parse 사이트에서 찾을 수 없다. (어쨌든 javascriptSDK가 아님).Parse.com javascriptSDK를 사용하여 이미지를 업로드하려면 어떻게해야합니까?

도움 주셔서 감사합니다.

답변

2

여기에 이미지를 업로드하는 방법에 대한 간단한 예입니다 :

<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> 
+0

좋은 대답에이 - 당신이 jQuery를 다운로드하는 것 같습니다 두번? – CharlesA

+0

@CharlesA - 잘 잡으세요! –

+0

parseFile.save()는 어떤 테이블을 저장합니까? – SuperUberDuper