Upload attachment
Upload attachment: uploadAttachment in the TypeScript, Python, Rust and Go clients.
POST /v1/projects/{id}/attachments
Uploads a file and returns its Attachment once ready to download.
photon.projects.uploadAttachment(input: UploadAttachmentInput, options?: RequestOptions): Promise<UploadAttachmentOutput>photon.projects.upload_attachment(input: UploadAttachmentInput, *, options: RequestOptions | None = None) -> models.Attachmentclient.upload_attachment(id: String, content_length: String, content_type: String, idempotency_key: String, body: &bytes::Bytes).await -> Result<ResponseValue<UploadAttachmentResponse>, Error<UploadAttachmentError>>client.Projects.UploadAttachment(ctx context.Context, params *UploadAttachmentParams, opts ...RequestOption) (*Attachment, error)import { Photon } from "@photon-ai/api";
const photon = new Photon({
headers: { Authorization: `Bearer ${process.env.PHOTON_API_TOKEN}` },
});
const result = await photon.projects.uploadAttachment({
path: {
id: "id",
},
headers: {
"content-length": "18",
"content-type": "text/plain",
"idempotency-key": "idempotency-key",
},
body: new Blob(["Hello from Photon."], { type: "text/plain" }),
});import os
from photon_api import Photon
from photon_api.rpc_generated import UploadAttachmentInput
photon = Photon(headers={"Authorization": f"Bearer {os.environ['PHOTON_API_TOKEN']}"})
result = photon.projects.upload_attachment(
UploadAttachmentInput.model_validate({
"path": {
"id": "id",
},
"headers": {
"content-length": "18",
"content-type": "text/plain",
"idempotency-key": "idempotency-key",
},
"body": b"Hello from Photon.",
})
)use photon_ai_api::{Credential, PhotonClientBuilder, SecretString};
let token = std::env::var("PHOTON_API_TOKEN")?;
let client = PhotonClientBuilder::new()
.credential("accountServiceKey", Credential::Bearer(SecretString::from(token)))
.build()?;
let result = client
.upload_attachment(
"id".to_owned(),
"18".to_owned(),
"text/plain".to_owned(),
"idempotency-key".to_owned(),
&"Hello from Photon.".into(),
)
.await
.map_err(|error| format!("{error:?}"))?
.into_inner();import (
"context"
"os"
"strings"
photonapi "github.com/photon-hq/api/packages/go"
)
ctx := context.Background()
client := photonapi.NewClient(photonapi.WithAPIKey(os.Getenv("PHOTON_API_TOKEN")))
result, err := client.Projects.UploadAttachment(ctx, &photonapi.UploadAttachmentParams{
ID: "id",
ContentLength: 18,
ContentType: "text/plain",
IdempotencyKey: "idempotency-key",
Body: strings.NewReader("Hello from Photon."),
})
if err != nil {
return err
}
_ = result{
"contentType": "string",
"createdAt": "2026-01-01T00:00:00Z",
"filename": "string",
"id": "string",
"metadata": {},
"projectId": "string",
"sizeBytes": 1,
"updatedAt": "2026-01-01T00:00:00Z"
}{
"contentType": "string",
"createdAt": "2026-01-01T00:00:00Z",
"filename": "string",
"id": "string",
"metadata": {},
"projectId": "string",
"sizeBytes": 1,
"updatedAt": "2026-01-01T00:00:00Z"
}Parameters
Reuse the same key and request for retries.
Returns
200 The attachment upload had already been committed. Attachment
201 The attachment was uploaded and committed. Attachment
Headers: Location. The raw response carries these headers; see Raw responses.