Laravel app Images are not visible

Hello, this is my fly.toml file:

# fly.toml app configuration file generated for one-sport on 2023-08-01T17:10:24+03:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "one-sport"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
primary_region = "waw"
console_command = "php /var/www/html/artisan tinker"

[build]
  [build.args]
    NODE_VERSION = "18"
    PHP_VERSION = "8.2"

[env]
  APP_ENV = "production"
  APP_DEBUG = "true"
  APP_URL = "https://one-sport.fly.dev/"
  LOG_CHANNEL = "stderr"
  LOG_LEVEL = "debug"
  LOG_STDERR_FORMATTER = "Monolog\\Formatter\\JsonFormatter"
  DB_CONNECTION = "mysql"
  DB_HOST = "mysql-my-new.internal"
  DB_PORT = 3306
  DB_DATABASE= "laravel-db"

  BROADCAST_DRIVER = "log"
  CACHE_DRIVER = "redis"
  FILESYSTEM_DISK = "public"
  QUEUE_CONNECTION = "sync"
  SESSION_DRIVER = "database"
  SESSION_LIFETIME = 120
  REDIS_URL = "redis://default:password@fly-frosty-tree-8896.upstash.io"
  MEMCACHED_HOST = "memcached"
  MAIL_MAILER = "smtp"
  MAIL_HOST = "sandbox.smtp.mailtrap.io"
  MAIL_PORT = 2525
  MAIL_ENCRYPTION = "tls"
  MAIL_FROM_ADDRESS = "info@my-lara-app.com"
  MAIL_FROM_NAME = "LaraApp Team"

[http_service]
  internal_port = 8080
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ["app"]

I manage images in my project with spatie media library.
Here is an example of code in the view:

<img src="{{ $product->getFirstMediaUrl('products/imageOne') }}" class="main_banner float-end" alt="product image">

So when I upload an image, sometimes it can be visible, but very often I see just an alt or empty space for image. And with time is going, all images can disappear. Where should I look for to resolve the problem?

Hi!

There’s likely 2 (ish) things going on to clarify.

  1. The first (most important) is that VM’s are ephemeral - any file you save to them (like when uploading images) won’t be around if the VM stops/starts.
    • You need to attach a volume and then save user-generated content (like uploaded files) to that volume - docs on that here
  2. Apps stop VM’s automatically when they are idle, fairly quickly. Sending a new request to the restarts the VM(s) automatically. This means your VM may have restarted/lost new data after a file was uploaded.

So, be sure to add a volume to persist data!

Thanks, a lot. For the explanation and for the link.