photo-front/documentation/api/PostPhotoUpload.markdown

4.4 KiB

Open Photo API / Photo Upload

OpenPhoto, a photo service for the masses


  1. Purpose
  2. Endpoint
  3. Parameters
  4. Examples
  1. Response

Purpose of the Photo Upload API

This API is used to upload a new photo for a user.


Endpoint

Authentication: required

POST /photo/upload.json

Parameters

  1. photo (required), The photo to be uploaded.
    • This can be the binary photo in multipart/formdata
    • This can be the base64 encoded value of the photo in application/x-www-form-urlencoded
  2. title (optional), i.e. My first day at work - A string title to describe the photo.
  3. description (optional), i.e. A much longer description of my first day - A string to describe the photo in detail.
  4. tags (optional), i.e. dog,cat - A comma delimited string of alpha numeric strings.
  5. dateUploaded (optional), i.e. 1311059035 - A unix timestamp of the date the photo was uploaded
  6. dateTaken (optional), i.e. 1311059035 - A unix timestamp of the date the photo was taken which overrides EXIF data if present
  7. latitude (optional), i.e. 34.76 - A decimal representation of latitude.
  8. longitude (optional), i.e. -87.45 - A decimal representation of longitude.
  9. returnSizes (optional), i.e. 200x200,300x300xBW - A string instructing specific versions of the photo to be autogenerated. To specify multiple sizes then separate each with a comman. The url will be present in the response.
    • 300x300 - A photo which maintains aspect ratio and fits inside a 300x300 square
    • 1024x768xCR - A photo that's exactly 1024x768 pixels cropped to the center in an optimized manner
    • 160x90xBWxCR - A photo that's cropped exactly to 160x90 in greyscale (black and white)

Examples

Command line curl

curl -F 'photo=@/path/to/photo.jpg' -F 'tags=dog,cat' http://jmathai.openphoto.me/photo/upload.json
curl -F 'photo=base64_encoded_string_representation_of_photo' -F 'title=My first day at work' http://jmathai.openphoto.me/photo/upload.json

PHP

$ch = curl_init('http://jmathai.openphoto.me/photo/upload.json');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt(
  $ch, 
  CURLOPT_POSTFIELDS, 
  array('photo' => '@/path/to/photo.jpg', 'tags' => 'dog,cat', returnOptions' => '300x300')
);
curl_exec($ch);

Response

The response is in a standard response envelope.

  • message, A string describing the result. Don't use this for anything but reading.
  • code, 202 on success
  • result, A Photo object

Sample

{
  "message":"Photo 8i uploaded successfully",
  "code":202,
  "result":{
     "id":"8i",
     "tags":[
        "dog",
        "cat"
     ],
     "pathBase":"\/base\/201107\/1311053366-huge.jpg",
     "appId":"opme",
     "host":"testjmathai1.s3.amazonaws.com",
     "dateUploadedMonth":"07",
     "status":"1",
     "hash":"6d7a9b0af31073a76ff2e79ee44b5c4951671fa2",
     "width":"4288",
     "dateTakenMonth":"07",
     "dateTakenDay":"03",
     "permission":"0",
     "pathOriginal":"\/original\/201107\/1311053366-huge.jpg",
     "exifCameraMake":"NIKON CORPORATION",
     "size":"5595",
     "dateTaken":"1309707719",
     "height":"2848",
     "views":"0",
     "dateUploadedYear":"2011",
     "dateTakenYear":"2011",
     "creativeCommons":"BY-NC",
     "dateUploadedDay":"18",
     "dateUploaded":"1311053403",
     "exifCameraModel":"NIKON D90",
     "longitude":"-89.24",
     "latitude":"37.65",
     "path300x300":"\/custom\/201107\/1311053366-huge_300x300.jpg",
  }
}