Image File Upload
This page uses the beta V3 scratch file and attachment endpoints. Set early_access="true" on the
client or send the EARLY-ACCESS: true header on raw HTTP requests. See the
V3 Stability Guidelines.
This example assumes io and httpx are imported, that benchling is a V3 SDK client (see
Getting started with the V3 SDK), and that
image_loader and cell come from an open XLSX worksheet, for instance
openpyxl’s image loader and a cell you have already located.
httpx is installed with the V3 SDK.
Get the image file
Get the image in question and write it into an in-memory buffer as PNG bytes. This example pulls an image out of a single cell in an XLSX worksheet.
Create a scratch file
A V3 upload starts with a scratch file. The response carries the
upload_urlthe bytes go to.Upload the file data
PUTthe raw PNG bytes to the upload URL with thex-amz-server-side-encryption: AES256header. TheContent-Typeheader on thisPUTbecomes the attachment’s MIME type. There is no base64 encoding and no MD5 hash, as there was with V2 blobs.Mark the upload finished
Set the scratch file’s
upload_statustoSUCCEEDEDso Benchling knows the bytes are in place.Create the attachment
Create an attachment from the scratch file.
generate_image_preview=Trueis what makes the attachment render as an image preview in the Benchling UI, as the V2VISUALIZATIONblob type did.Persist the attachment ID
Collect the attachment ID so you can reference it later. This example uses it in calls to assay results, but persisting it matters for every use case: attachments are not searchable on their own, so an unrecorded ID means re-uploading the file.
To link the attachment to a schema field, or to put the image into the body of a notebook entry, see Uploading an Attachment to Benchling. For large files, see Large Attachment Upload.