Upload an Image
In this guide, we walk through how to upload an image to a PhotoShelter account.
What you need
- An API key with PhotoShelter, which is required to access the API. To run the example code in this guide, replace "MY_API_KEY" with your own key. Register for an API key.
- Access to a PhotoShelter account. If you don't have one, you can sign up for a free Starter Account. Starter Accounts have limited storage and theme options, but it will allow you to test the PhotoShelter API.
What to do
Authenticate the user
You need to be authenticated via the endpoint /psapi/v3/mem/authenticate before you can upload an image through the PhotoShelter API.
curl -c cookie.txt -Femailemail@example.com -Fpassword=supersecretpassword -Fmode=cookie -Fapi_key=MY_API_KEY https://www.photoshelter.com/psapi/v3/mem/authenticate
Post the image
Let’s say that you want to upload an image with the path "/my/file/path/my_image.jpg". To upload the image, make a request to the endpoint /psapi/v3/mem/image/upload, with the data encoded using HTTP multipart/form-data encoding type. In curl, be sure to prefix the file path with
@, which makes curl load the file data.
curl -b cookie.txt -F'@/my/file/path/my_image.jpg' http://www.photoshelter.com/psapi/v3/mem/image/upload?api_key=MY_API_KEY&gallery_id=MY_GALLERY_ID
If successful, the API returns data about the image, including the new image id.
What you should know
You can upload more than one file at a time by setting the
file parameter to a form array.