Working with Attachments
Beta APIs
The Document APIs are beta. Send the EARLY-ACCESS: true header on every request shown here; without it these endpoints are unavailable. See Introduction to Documents and the Stability Guidelines.
Documents can reference file attachments anywhere in their content.
Attaching a file to a document
To attach a file to a document, first upload the file into Benchling as a scratch file.
To upload and attach the file:
-
Create the scratch file that defines an upload location. From the response, retrieve the
uploadUrland theid. TheuploadUrlis a presigned S3 URL with a short expiration time. The response includes an expiration header. -
Use a client of your choice to upload your file to the presigned URL. S3 expects a
PUTrequest to the presigned URL with the binary data of the file in the request body. -
Finalize the scratch file’s
uploadStatusto indicate that the file has been uploaded to S3.If your
uploadUrlexpires before you upload, fetch the scratch file again for a new presigned URL. -
Insert any scratch file with
uploadStatus: "SUCCEEDED"into a document using apartsMutationsuch asinsert.
Downloading a file from a document
To download a document attachment, use the download.url of its attachment part. Fetch the document’s content to retrieve it. The URL is a presigned S3 URL with a short expiration time, given in download.expiresAt. If antivirus scanning blocks the file, download is null; scanStatus shows the scan result.