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 Trial Account. Trial Accounts have limited storage and theme options, but it will allow you to test the PhotoShelter API for up to 14 days. If you need an extension on the trial, reach out to our Technical Support team.
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 email=me@example.com \ -F password=supersecretpassword \ -F mode=cookie \ https://www.photoshelter.com/psapi/v3/mem/authenticate
For more information on user authentication, you can follow the User Authentication guide or read the documentation on connecting to the PhotoShelter API.
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.
Further Reading
- /psapi/v3/mem/image/upload endpoint reference documentation
- /psapi/v3/mem/authenticate endpoint reference documentation
- User Authentication Guide
- Connecting to the PhotoShelter API