How do I get access to the storage attached to the application?

Issues information

Your issue

How do I get access the storage attached to the application? I can’t figure it out from docs

Let’s say I want user to upload avatars in my app, can I use the storage for that? And if so, how would it be accessible from a front-end? I am using sirv that points to /static folder. In my build folder I want to upload user generated images to that static folder, but that would just be in my deployed app, which is ephemeral?

So anyway I am a little hazy on how I can use the storage app and be able to write to it with Node and also have access to it from the client.

I am a little confused by the “mount point” and just how persistent storage works in general?

Hi Daniil,

Indeed, in your current case you are better to use persistent storage provided by Qovery. From what I see you forget the size unit in your .qovery.yml

---
application:
  name: "union-booth"
  project: "union-booth"
  organization: "QoveryCommunity"
  storage:
  - name: "static"
    size: "200" << MB? 
    type: "fast_ssd"
    mount_point: "/mnt/static"
databases:
- type: "POSTGRESQL"
  name: "union-booth"
  version: "11"
routers:
- name: "main-union-booth"
  routes:
  - application_name: "union-booth"
    paths:
    - "/*"

Note: on the community plan (free) you are limited to 10GB. So the correct configuration is:

---
application:
  name: "union-booth"
  project: "union-booth"
  organization: "QoveryCommunity"
  storage:
  - name: "static"
    size: "10GB"
    type: "fast_ssd"
    mount_point: "/mnt/static"
databases:
- type: "POSTGRESQL"
  name: "union-booth"
  version: "11"
routers:
- name: "main-union-booth"
  routes:
  - application_name: "union-booth"
    paths:
    - "/*" 

My 2 cents: If your idea is to expose images online, then I would suggest you use an object storage solution like AWS S3 or Digital Ocean Spaces instead of local block storage. This is much more appropriate for many technical reasons and very simple to use. I can develop this point if you want.

Thank you for a quick response, Romaric! I believe that 200 actually came from auto-generated .qovery.yml file, not something I added manually, in case you guys want to look into it.

So basically if I understand correctly I can’t use the block storage on the client? It’s just something that only server can have access to?

But in either case, this might be a naive question, but how do I even use the block storage? What would be the path to it, I guess from my root? Or they are not even in the same container? That’s the part I am a little hazy on.

Can you open a #bugs issue then we can take a look? Thank you.

Your app can access this storage - the goal of persistent storage is to keep your data available even if your app is restarted. But it will not keep your data if your app is deleted.

The path to get access to your storage is /mnt/static as declared in your .qovery.yml file. It means that everything your app puts in /mnt/static will be stored on this persistent storage.

Gotcha. Thank you. Bug created.

1 Like

Let me know if it works :slight_smile: Have a good day

Yep, I figured it out, this is what I ended up doing,

For my serve-static middleware:

const serveStatic = require('serve-static');

const prod = NODE_ENV === 'production';
app.use(
  serveStatic(prod ? path.resolve(__dirname, '/mnt/static') : 'static')
)

and in my file writing code pretty much the same:

const avatarsFolder = NODE_ENV === 'production'
  ? path.resolve(__dirname, '/mnt/static/avatars')
  : path.resolve(__dirname, './static/avatars');

  fs.writeFileSync(
    `${avatarsFolder}/${USER_AVATAR_FILE}.svg`,
    ${USER_AVATAR_FILE_DATA}
  );
}
1 Like