Hi, quite new here to Palantir Foundry. just a few questions regarding ontology objects with attachments. I am using this function createAttachmentUpload to upload attachments. What function in the OSDK can I use to retrieve the attachment based on rid? Do we have documents on how to manipulate attachments from the OSDK?
I also have an edit function that accepts an attachment parameter. How can I change the attachment without reuploading? For example, I want to change the attachment property of an object from attachment A to attachment B, where attachment B has already been uploaded before.
const result = await client(editObj).applyAction(
{
Obj: {
$primaryKey,
$apiName: "Obj",
$objectType: "",
$title: undefined,
},
file, //what to pass here?
another_property,
},
If you look at the API documentation on your Dev console application, you will find Uploading Attachments section which explains how to do that.
async function uploadMyFile() {
const file = await fetch("file.json");
const blob = await file.blob();
return createAttachmentUpload(blob, "myFile");
}
and in your action you do something like this:
import { addPermit } from "@osdk-sample-app-20/sdk";
import { AttachmentUpload } from "@osdk/api";
const attachment: AttachmentUpload = uploadMyFile();
const result = await client(addPermit).applyAction(
{
"Aircraft": { $primaryKey: primaryKeyValue, /* other properties */ },
"permit": attachment
},
{
$returnEdits: true,
}
);
if (result.type === "edits") {
// for new objects and updated objects edits will contain the primary key of the object
const updatedObject = result.editedObjectTypes[0];
console.log("Updated object", updatedObject);
}
I am familiar with fetchContents()
const objValue = objValue.attachmentProperty.fetchContents()
but is there a more direct way based on the rid, like downloadAttachment(rid)?
alright, thanks! is there a function in the osdk to read back the uploaded attachment given its rid? another API will be reading it, is there a function like readAttachment?
If you search the API documentation on our public web site you can find this method
Get Attachment Property Content By Rid
Which I think is what you are looking for.
You can write a fetch function to call this API and use the token you are granted in the SDK by calling auth.getTokenOrNothing()