Write to a text file in a POD in CSS

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.

final editResponse = await http.patch(
    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

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.

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?

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

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

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

Here’s an example usage that adds a webId to a group (from here):

  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,
1 Like

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

1 Like