# Write to a text file in a POD in CSS

**URL:** <https://forum.solidproject.org/t/write-to-a-text-file-in-a-pod-in-css/6624>\
**Category:** General Discussion\
**Created:** [June 8, 2023, 3:33am UTC](https://forum.solidproject.org/t/write-to-a-text-file-in-a-pod-in-css/6624 "2023-06-08T03:33:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anushka](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/anushka/32/3134_2.png) [@Anushka](https://forum.solidproject.org/u/Anushka)\
**Post date:** [June 8, 2023, 3:33am UTC](https://forum.solidproject.org/t/write-to-a-text-file-in-a-pod-in-css/6624/1 "2023-06-08T03:33:52Z")

</div>

Hi all,

If I want to write to a text file in a POD in CSS (simply write a line of string) using an http request how would I do it? I have the following patch request, but it does not work. The server is throwing me `415: UnsupportedMediaTypeHttpError` error. I cannot do a put request because it will simply replace what’s already in the file. I just need to write a new line of string to the file.

```auto
final editResponse = await http.patch(
    Uri.parse(textFileUrl),
    headers: <String, String>{
      'Accept': '*/*',
      'Authorization': 'DPoP $accessToken',
      'Connection': 'keep-alive',
      'Content-Type': 'text/plain',
      'DPoP': dPopToken,
    },
    body: dataLineString,
  );

```

Any help in this would be much appreciated.

Thank you, Anushka

---

<div class="post-metadata">

**Author:** ![Vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@Vincent](https://forum.solidproject.org/u/Vincent)\
**Post date:** [June 8, 2023, 4:56am UTC](https://forum.solidproject.org/t/write-to-a-text-file-in-a-pod-in-css/6624/2 "2023-06-08T04:56:58Z")

</div>

Unfortunately you cannot do that with a PATCH, but you can do a GET, append the string to the response body, and then PUT that.

---

<div class="post-metadata">

**Author:** ![Anushka](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/anushka/32/3134_2.png) [@Anushka](https://forum.solidproject.org/u/Anushka)\
**Post date:** [June 8, 2023, 9:03am UTC](https://forum.solidproject.org/t/write-to-a-text-file-in-a-pod-in-css/6624/3 "2023-06-08T09:03:15Z")

</div>

Hi @Vincent, thanks for your reply. Yes, that’s a workaround. However, that wouldn’t be possible with only Write access to the file I assume?

---

<div class="post-metadata">

**Author:** ![Vincent](https://avatars.discourse-cdn.com/v4/letter/v/e9bcb4/32.png) [@Vincent](https://forum.solidproject.org/u/Vincent)\
**Post date:** [June 8, 2023, 9:20am UTC](https://forum.solidproject.org/t/write-to-a-text-file-in-a-pod-in-css/6624/4 "2023-06-08T09:20:28Z")

</div>

Write access should be sufficient, but unfortunately Append access wouldn’t be.

---

<div class="post-metadata">

**Author:** ![Anushka](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/anushka/32/3134_2.png) [@Anushka](https://forum.solidproject.org/u/Anushka)\
**Post date:** [June 8, 2023, 9:36am UTC](https://forum.solidproject.org/t/write-to-a-text-file-in-a-pod-in-css/6624/5 "2023-06-08T09:36:44Z")

</div>

Yes, sorry Append access wouldn’t be possible in this case. Thanks for the clarification.

---

<div class="post-metadata">

**Author:** ![A\_A](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/a_a/32/786_2.png) [@A\_A](https://forum.solidproject.org/u/A_A)\
**Post date:** [June 8, 2023, 1:44pm UTC](https://forum.solidproject.org/t/write-to-a-text-file-in-a-pod-in-css/6624/6 "2023-06-08T13:44:11Z")

</div>

If you store the data as rdf (eg text/turtle) you could use a n3 patch to add this entry. Here’s the specification: [Solid Protocol](https://solidproject.org/TR/protocol#n3-patch)

Here’s an example usage that adds a webId to a group (from [here](https://github.com/solidcryptpad/solidcryptpad/blob/74f93fee06fcb93b454f6004863647ef11e9c24f/src/app/services/file-handler/solid-file-handler.service.ts#L240-L264)):

```typescript
  async addCurrentUserToGroup(groupUrl: string) {
    const webId = await this.authService.getWebId();
    const n3Patch = `
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
@prefix vcard: <http://www.w3.org/2006/vcard/ns#>.

_:addAccess a solid:InsertDeletePatch;
  solid:inserts { <${groupUrl}> vcard:hasMember <${webId}>. }.
`;

    await this.authService.authenticatedFetch(groupUrl, {
      method: 'PATCH',
      headers: {
        'content-type': 'text/n3',
      },
      body: n3Patch,
    });
  }

```

---

<div class="post-metadata">

**Author:** ![jeffz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jeffz/32/600_2.png) [@jeffz](https://forum.solidproject.org/u/jeffz)\
**Post date:** [June 8, 2023, 4:29pm UTC](https://forum.solidproject.org/t/write-to-a-text-file-in-a-pod-in-css/6624/7 "2023-06-08T16:29:20Z")

</div>

It is also possible to create a new turtle file with the same N3 patch.
