New Admins: Register for our new Pure Lecture Series!
Pure's logos
Pure Help Center for Pure Administrators

If you are a researcher, or other non-admin at your institution, click here.

  • Home
  • Announcements
  • Release Notes
  • Technical user guides
  • Training
  • Events
  • Support
  • Contact Us
  • Home
  • Training
  • Technical user guides
  • Pure API
  • API Examples

How Can We Help?

Search Results

Filter By Category

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Contact us

Pure API: Uploading files Pure API: Uploading files

Introduction

A common mistake when uploading files to Pure using the Pure API is bad usage of mime type headers. Pure currently only supports uploading one file at a time, with a specific mime type. Pure does not understand upload data with content-type set to multipart/....

 

Multipart file upload is not supported in the Pure write API

 

 

Code libraries (like Python requests) support uploading both raw files and multipart. It also supports manually setting the content-type on a PUT request to e.g. image/jpeg.

Requirements

  • Pure Admin Account 
  • Valid API Key 
  • API Documentation
  • Python

 

Expertise Level

Knowledge of Python is required. See also Python API Requests: Fundamental Coding Examples 

 

Examples

There are three typical combinations of doing this (examples shown below):

Example 1: WORKS. 

In this example, we set the content-type header to image/jpeg on the put request and add the raw image binary data, using the data parameter in the requests.put(...) function.

Example 2: Does NOT work

In this example we do not set a header on the PUT request and we are using the files parameter in the requests.put(...) function. In this case, the requests library will automatically add the multipart/... header. Pure will see this header and return an HTTP error code 400 with an error description.

Example 3: Does NOT work.

In this example we set the content-type header to image/jpeg on the PUT request and add multipart data, using the files parameter in the requests.put(...) function. In this case, the requests library will not automatically set the content-type to multipart/..., as it is manually set. Pure will accept the content-type header image/jpeg and upload the binary data as an image. Since the multipart/... header data is included in the data, the file is unable to be shown as an image.

Only example 1 works. Example 2 will fail with an error message when trying, but example 3 will fail silently and upload a corrupted image file.

Python examples

The three examples mentioned in the section above are shown here, written in Python.

These examples are just that, examples. They must be used at your own risk, and Elsevier will not support or review code that is using this or is based on this.

 

 

import requests

photo_file_path = "../resources/upload_test.jpg"

with open(photo_file_path, 'rb') as file:

    ################################################################################
    # Example 1: Works. Binary file upload.
    headers = {
        "accept": "application/json",
        "api-key": "insert here",
        "content-type": "image/jpeg"
    }
    response = requests.put("<server URL>/ws/api/persons/file-uploads", headers=headers, data=file)
    print("Response code:", response.status_code)
    print("Response text:", response.text)



    ################################################################################
    # Example 2: DOES NOT WORK. It will return error code 400 with an error description.
    headers = {
        "accept": "application/json",
        "api-key": "insert here"
        # Omitting the multipart/form-data header, as the "requests" library will automatically add it.
    }
    files = {'file': (photo_file_path, file, 'image/jpeg')} # Multipart specification
    response = requests.put("<server URL>/ws/api/persons/file-uploads", headers=headers, files=files)
    print("Response code:", response.status_code)
    print("Response text:", response.text)



    ################################################################################
    # Example 3: DOES NOT WORK. The request will go through as mime type is forced to be "image/jpeg", but the uploaded
    # JPEG file will be corrupted, as the multipart header (that Python adds when using "files=...") will be considered part
    # of the binary data of the image.
    headers = {
        "accept": "application/json",
        "api-key": "insert here",
        "content-type": "image/jpeg" # Forcing the mimetype to "image/jpeg".
    }
    files = {'file': (photo_file_path, file, 'image/jpeg')} # Multipart specification
    response = requests.put("<server URL>/ws/api/persons/file-uploads", headers=headers, files=files)
    print("Response code:", response.status_code)
    print("Response text:", response.text)

 

Published at February 13, 2025

Download
Table of Contents
  1. Introduction
  2. Requirements
  3. Expertise Level
  4. Examples
  5. Example 1: WORKS.
  6. Example 2: Does NOT work
  7. Example 3: Does NOT work.
  8. Python examples
Related Articles
  • Pure API: Working with files
  • Pure API: Access definitions for content and field filtering
  • Getting started: Pure API user guide
Keywords
  • simple integration
  • file upload
  • python
  • pure api
  • api examples
  • write api
  • file upload api

Was this article helpful?

Yes
No
Give feedback about this article

    About Pure

  • Announcements

    Additional Support

  • Events
  • Client Community
  • Training

    Need Help?

  • Contact Us
  • Submit a Support Case
  • My Cases
  • Linkedin
  • Twitter
  • Facebook
  • Youtube
Elsevier logo Relx logo

Copyright © 2025 Elsevier, except certain content provided by third parties.

  • Terms & Conditions Terms & Conditions
  • Privacy policyPrivacy policy
  • AccesibilityAccesibility
  • Cookie SettingsCookie Settings
  • Log in to Pure Help CenterLog in to Helpjuice Center

Knowledge Base Software powered by Helpjuice

Expand