Advertisement
Filkolev

Uploading picture to Parse.com

Apr 16th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function () {
  2.     var image;
  3.  
  4.     $('button').on('click', function () {
  5.         var file = $('#file')[0].files[0];
  6.        
  7.             $.ajax({
  8.                 method: 'POST',
  9.                 url: 'https://api.parse.com/1/files/pic.jpg',
  10.                 headers: {
  11.                     'X-Parse-Application-Id': 'U7rDk3WOeckRW7TvByLfu1sd2K996BdCwkzXUejH',
  12.                     'X-Parse-REST-API-Key': 'vsRKxqdSdeDV5O5ABV9BXER3S5eUm39K36bt5g0z',
  13.                     'Content-Type': 'image/jpeg'
  14.                 },
  15.                 data: file,
  16.                 processData: false
  17.             }).success(function (data) {
  18.                 var imgName = data.name;
  19.  
  20.                 var updateData = JSON.stringify({
  21.                     "pic": {
  22.                         "name": imgName,
  23.                         "__type": "File"
  24.                     }
  25.                 });
  26.  
  27.                 $.ajax({
  28.                     method: 'PUT',
  29.                     url: 'https://api.parse.com/1/classes/Product/R9IGMQU21J',
  30.                     headers: {
  31.                         'X-Parse-Application-Id': 'U7rDk3WOeckRW7TvByLfu1sd2K996BdCwkzXUejH',
  32.                         'X-Parse-REST-API-Key': 'vsRKxqdSdeDV5O5ABV9BXER3S5eUm39K36bt5g0z',
  33.                         'Content-Type': 'application/json'
  34.                     },
  35.                     data: updateData
  36.                 }).success(function (response) {
  37.                     console.log(response);
  38.                 }).error(function (err) {
  39.                     console.log(err.message);
  40.                 });
  41.             }).error(function (err) {
  42.                 console.log(err.message);
  43.             });      
  44.     });
  45. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement