Strapi media lost after deploy

Hello!

Im hosting a strapi on render with attached disk

But each time I deployed my strapi project, media are removed
I checked in the shell and there is an empty folder

I have a folder: public/uploads/.gitkeep

Is there a way to preserve that folder ?

Thank you

Hi Johan,

In order for your uploads folder to persist to the disk you have to set the disk path to /opt/render/project/src/public/uploads. Let me know if that fixes things for you!

Hi Tyler

Thanks for your answer

I think I m missing some config in the render.yaml

This was my original file:

services:
  - type: web
    name: strapi
    env: node
    plan: starter
    buildCommand: yarn install && yarn build
    startCommand: rsync -a public/ /data/public/ && yarn start
    healthCheckPath: /_health
    disk:
      name: strapi-data
      mountPath: /data
      sizeGB: 1
    envVars:
      - key: NODE_VERSION
        value: 16.13.2
      - key: NODE_ENV
        value: production
      - key: DATABASE_FILENAME
        value: /data/strapi.db
      - key: JWT_SECRET
        generateValue: true
      - key: ADMIN_JWT_SECRET
        generateValue: true

And the fix I tried:

services:
  - type: web
    name: strapi
    env: node
    plan: starter
    buildCommand: yarn install && yarn build
    startCommand: rsync -a public/ && yarn start
    healthCheckPath: /_health
    disk:
      name: strapi-data
      mountPath: /opt/render/project/src/public/uploads
      sizeGB: 1
    envVars:
      - key: NODE_VERSION
        value: 16.13.2
      - key: NODE_ENV
        value: production
      - key: DATABASE_FILENAME
        value: /opt/render/project/src/public/strapi.db
      - key: JWT_SECRET
        generateValue: true
      - key: ADMIN_JWT_SECRET
        generateValue: true

Now it s also reseting my db…

Maybe i missed some conf in middleware

Unfortunately documentation seems outdated

It s weird because i see media files in the shell, but I don t have access through strapi admin after redeploy

I finally succeed !
Thanks Tyler for the help

Because the render-strapi-sqlite starter project is outdated make sure to have this:


services:
  - type: web
    name: strapi
    env: node
    plan: starter
    buildCommand: yarn install && yarn build
    startCommand: rsync -a public/ && yarn start
    healthCheckPath: /_health
    disk:
      name: strapi-data
      mountPath: /opt/render/project/src/public/uploads
      sizeGB: 1
    envVars:
      - key: NODE_VERSION
        value: 16.13.2
      - key: NODE_ENV
        value: production
      - key: DATABASE_FILENAME
        value: /opt/render/project/src/public/uploads/strapi.db
      - key: JWT_SECRET
        generateValue: true
      - key: ADMIN_JWT_SECRET
        generateValue: true

and for config/database.js

const path = require('path');

module.exports = ({ env }) => ({
  connection: {
    client: 'sqlite',
    connection: {
     filename: env('DATABASE_FILENAME', '.tmp/data.db'),
    },
    useNullAsDefault: true,
  },
});

I know this is an old topic, but in case some new Render+Strapi users are stumbling upon it: do not apply the accepted answer. It is dangerous, since it exposing the db file publicly.

The orignal file posted by the OP is correct. I think the issue was a misconfigured env and / or wrong connection.filename in config/database.