Skip to content

Permission denied error when using puter.fs from @heyputer/puter.js #2132

@bitsnaps

Description

@bitsnaps

Looking at the example from doc, I created a new project with .env containing my api key and loaded using dotenv, and trying different variations to write a file: (puter.fs.write('hello.txt'...), puter.fs.write('./hello.txt'..), puter.fs.write('~/hello.txt'..), puter.fs.write('<FULL_PATH>/hello.txt'..)... it always ends with error, here is my last attempt:

import { init } from "@heyputer/puter.js/src/init.cjs";
import "dotenv/config";

const puter = init(process.env.puterAuthToken); // uses your auth token

const username = await puter.getUser().then(info => info.username)
console.log(`Welcome back :${username}!`);

const dirPath = `/${username}/Public`;

// Create a file
puter.fs
  .write(`${dirPath}/hello.txt`, 'Hello, world!')
  .then(() => {
    console.log("File written successfully");
  })
  .catch((error) => {
    console.log("Error writing file:", error);
  });

Here is the current log:

Error writing file: {
  code: 'forbidden',
  '$': 'heyputer:api/APIError',
  message: 'Permission denied.',
  status: 403
}

This error is root cause of this issue.

I don't know if the @heyputer/puter.js is supposed to have the same API for the client library since it requires to be initialized with init, or if we can you make it loads puterAuthToken directly from the env var ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions