Skip to content

Instantly share code, notes, and snippets.

@kyletolle
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyletolle/9474143 to your computer and use it in GitHub Desktop.
Save kyletolle/9474143 to your computer and use it in GitHub Desktop.
Uploading a photo to Fulcrum from Python
// This is the response from the call, reformatted for readability.
{
"photo": {
"access_key": "f37be52e-06d2-418a-916d-0e5874a0de29",
"created_at": "2014-03-10T20:54:26Z",
"created_by": "Kyle Tolle",
"created_by_id": "51efe7d6a93448fc300048d9",
"exif": {
"pixel_x_dimension": 1090,
"pixel_y_dimension": 1038,
"resolution_unit": 2,
"x_resolution": "144.0",
"y_resolution": "144.0"
},
"form_id": null,
"large": "https://web.fulcrumapp.com/api/v2/photos/f37be52e-06d2-418a-916d-0e5874a0de29/large.jpg",
"latitude": 0.0,
"longitude": 0.0,
"record_id": null,
"thumbnail": "https://web.fulcrumapp.com/api/v2/photos/f37be52e-06d2-418a-916d-0e5874a0de29/thumbnail.jpg",
"updated_at": "2014-03-10T20:54:26Z",
"url": "https://web.fulcrumapp.com/api/v2/photos/f37be52e-06d2-418a-916d-0e5874a0de29.jpg"
}
}
import urllib, urllib2, uuid
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
def upload_photo():
register_openers()
url = "https://web.fulcrumapp.com/api/v2/photos.json"
access_key = uuid.uuid4()
values = {'photo[file]':open('some_photo.jpg'), 'photo[access_key]':access_key}
data, headers = multipart_encode(values)
headers['User-Agent'] = 'My Application Name'
headers['X-ApiToken'] = 'My API Token Goes Here'
request = urllib2.Request(url, data, headers)
response = urllib2.urlopen(request)
the_response = response.read()
print the_response
upload_photo()
https://web.fulcrumapp.com/api/v2/photos/f37be52e-06d2-418a-916d-0e5874a0de29.jpg?token=MyAPITokenTokenGoesHere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment