What path to access volume storage?

So I have volume named save set up. I used fs.writeFile("save/name.txt", ...) to create a file inside it, but when I examined with fly ssh console it created a file in app/save directory. And it looks like the volume storage is at top level. How should I change the file path to access it?

1 Like

I don’t use volumes on Fly, but I’d imagine if you specify the absolute path to the mount point of your volume in fs.writeFile, then it should work like you intend it to.

const mnt = "/my/volume/mount/point";
const dirent = "save";
const fname = "name.txt";
const abspath = path.format({
        dir: path.join([mnt, dirent]),
        base: fname,
    });
fs.writeFile(
        abspath,
        ...
    );

Correct, but there is one more piece to the puzzle. See: Fly Volumes overview · Fly Docs.

Step 1 is to create a volume and give it ia name. In this case save.

Step 2 is to associate that volume with a path by adding lines in your fly.toml (that’s the link above).

Step 3 is to write to that path. Node the code above assumes that a directory named save was created on that volume, if that is what you wish to do, make sure that directory is created before executing the code above. If you don’t need that directory, const abspath = path.join(mnt, fname) will do just fine.

2 Likes

Yes, I think I’ve done Step 2 as well.

[mounts]
  source="save"
  destination="/save"

So the mount point should be save? But if I write to save/name.txt, it just creates a folder under app and writes it there as app/save/name.txt

Hi @bluekite, have you tried /save/name.txt? save/name.txt is relative to your working directory, which appears to be /app.

2 Likes

This solved the problem, thank you! Can’t believe I didn’t know this…

2 Likes

Hi @rubys can you explain where in the documentation do you folks specify the fly.toml file? I’ve been looking at the link you provided and others and I do not see where to specify the mount fly.toml section you included here… I spent 1 hr trying to debug my mnt issue which is similar to this one… the documentations are not updated.

Also see Fly Volumes overview · Fly Docs