Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. $image['tmp_name'] = "/tmp/unnamed.png";
  2. $image['file_image'] = base64_encode(file_get_contents("/tmp/unnamed.png"));
  3. $image['name'] = "unnamed.png";
  4. $image['file_name'] = "unnamed.png";
  5. $image['type'] = "image/png";
  6. $image['submit'] = "UPLOAD";
  7.  
  8. $url = 'http://localhost/api/upload_image';
  9.  
  10. $postdata = http_build_query(
  11. array(
  12. 'file_name' => 'form variable1',
  13. 'file_image' => file_get_contents($image['tmp_name'])
  14. )
  15. );
  16.  
  17. $opts = array('http' =>
  18. array(
  19. 'method' => 'POST',
  20. 'header' => 'Content-Type: multipart/form-data',
  21. 'content' => $postdata
  22. )
  23. );
  24.  
  25. $context = stream_context_create($opts);
  26.  
  27. var_export(file_get_contents($url, false, $context));
  28.  
  29. class UploadImage(webapp.RequestHandler):
  30. def post(self):
  31. img = Images()
  32. img.image = self.request.get('file_image')
  33. img.name = self.request.get('file_name') or "no name"
  34. img.put()
  35.  
  36. self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
  37. self.response.out.write('{"status": "OK", "image": "'+img.key.urlsafe()+'"}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement