5.5 KiB
5.5 KiB
Upload Photo
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
(Due to a bug in PHP's PECL OAuth extension all parameters except for the photo must be passed urlencoded in the query string. This only applies for multipart and not application/x-www-form-urlencoded requests).
- 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
- permission (optional), 0 for private and 1 for public.
- title (optional), e.g. My first day at work - A string title to describe the photo.
- description (optional), e.g. A much longer description of my first day - A string to describe the photo in detail.
- tags (optional), e.g. dog,cat - A comma delimited string of alpha numeric strings.
- dateUploaded (optional), i.e. 1311059035 - A unix timestamp of the date the photo was uploaded
- dateTaken (optional), e.g. 1311059035 - A unix timestamp of the date the photo was taken which overrides EXIF data if present
- license (optional), e.g. CC BY-SA or My Custom License - A string representing a custom or Creative Commons license.
- latitude (optional), e.g. 34.76 - A decimal representation of latitude.
- longitude (optional), e.g. -87.45 - A decimal representation of longitude.
- returnSizes (optional), e.g. 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 (using openphoto-php)
source secrets.sh
./openphoto -p -X POST -h current.openphoto.me -e /photo/upload.json -F 'photo=@/path/to/photo.jpg' -F 'tags=sunnyvale,downtown'
PHP (using openphoto-php)
// multipart
$client = new OpenPhotoOAuth($host, $consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret);
$response = $client->post("/photo/upload.json", array('photo' => '@/path/to/photo.jpg', 'tags' => 'sunnyvale,downtown'));
// base64 encoded
$photoBase64Encoded = base64_encode(file_get_contents('/path/to/photo.jpg'));
$response = $client->post("/photo/upload.json", array('photo' => $photoBase64Encoded, 'tags' => 'sunnyvale,downtown'));
Python (using openphoto-python)
# multipart
client = openphoto.OpenPhoto()
client.photo.upload("path/to/photo.jpg", tags=["sunnyvale", "downtown"])
# base64 encoded
client.photo.upload_encoded("path/to/photo.jpg", tags=["sunnyvale", "downtown"])
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",
}
}