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, or learn more about Connecting to the PhotoShelter API.
- 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 \ -H "X-PS-Api-Key: MY_API_KEY" \ -F firstname.lastname@example.org \ -F password=supersecretpassword \ -F mode=cookie \ 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 \ -H "X-PS-Api-Key: MY_API_KEY" \ -F gallery_id=MY_GALLERY_ID \ -F 'file=@/my/file/path/my_image.jpg' \ https://www.photoshelter.com/psapi/v3/mem/image/upload
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.