# Editing objects with attachments

**URL:** <https://community.palantir.com/t/editing-objects-with-attachments/2441>\
**Category:** Ask the Community\
**Tags:** osdk\
**Created:** [January 6, 2025, 4:17pm UTC](https://community.palantir.com/t/editing-objects-with-attachments/2441 "2025-01-06T16:17:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![apr\_flaxie](https://yyz1.discourse-cdn.com/palantir/user_avatar/community.palantir.com/apr_flaxie/32/2128_2.png) [@apr\_flaxie](https://community.palantir.com/u/apr_flaxie)\
**Post date:** [January 6, 2025, 4:17pm UTC](https://community.palantir.com/t/editing-objects-with-attachments/2441/1 "2025-01-06T16:17:51Z")

</div>

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.

```auto
const result = await client(editObj).applyAction(
      {
        Obj: {
          $primaryKey,
          $apiName: "Obj",
          $objectType: "",
          $title: undefined,
        },
        file, //what to pass here?
        another_property,
      },

```

---

<div class="post-metadata">

**Author:** ![ewitkon](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@ewitkon](https://community.palantir.com/u/ewitkon)\
**Post date:** [January 6, 2025, 6:12pm UTC](https://community.palantir.com/t/editing-objects-with-attachments/2441/2 "2025-01-06T18:12:59Z")

</div>

If you look at the API documentation on your Dev console application, you will find `Uploading Attachments` section which explains how to do that.

```auto
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:

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![apr\_flaxie](https://yyz1.discourse-cdn.com/palantir/user_avatar/community.palantir.com/apr_flaxie/32/2128_2.png) [@apr\_flaxie](https://community.palantir.com/u/apr_flaxie)\
**Post date:** [January 7, 2025, 8:01am UTC](https://community.palantir.com/t/editing-objects-with-attachments/2441/3 "2025-01-07T08:01:59Z")

</div>

I am familiar with fetchContents()

const objValue = objValue.attachmentProperty.fetchContents()

but is there a more direct way based on the rid, like downloadAttachment(rid)?

---

<div class="post-metadata">

**Author:** ![apr\_flaxie](https://yyz1.discourse-cdn.com/palantir/user_avatar/community.palantir.com/apr_flaxie/32/2128_2.png) [@apr\_flaxie](https://community.palantir.com/u/apr_flaxie)\
**Post date:** [January 7, 2025, 8:02am UTC](https://community.palantir.com/t/editing-objects-with-attachments/2441/4 "2025-01-07T08:02:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ewitkon](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@ewitkon](https://community.palantir.com/u/ewitkon)\
**Post date:** [January 7, 2025, 2:17pm UTC](https://community.palantir.com/t/editing-objects-with-attachments/2441/5 "2025-01-07T14:17:55Z")

</div>

If you search the API documentation on our public web site you can find this method  
[Get Attachment Property Content By Rid](https://www.palantir.com/docs/foundry/api/ontologies-v2-resources/attachment-properties/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()`

---

<div class="post-metadata">

**Author:** ![system](https://yyz1.discourse-cdn.com/palantir/user_avatar/community.palantir.com/system/32/3_2.png) [@system](https://community.palantir.com/u/system)\
**Post date:** [March 8, 2025, 2:17pm UTC](https://community.palantir.com/t/editing-objects-with-attachments/2441/6 "2025-03-08T14:17:58Z")

</div>

Closed on March 8, 2025, 2:17pm UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
