Can media files be kept only one copy?

In kirby 3, I found that after uploading a file, it will exist in both the content and media folders. My website has 200Mb of files, but it actually takes up 400Mb of space. Can I keep only one copy?

Yes, you could serve your files from the content folder if you don’t move it out of the web root. See Image URLs - How to remove string?. Read the complete answer for why we copy though.

I would suggest not modifying the the natural behaviour of kirby. As @texnixe suggests, you can serve them from the content folder and id like to share what i did with it:

'components' => [
    'file::url' => function (Kirby $kirby, $file) {
      $page = $file->parent();
      if (preg_match('/album\/|album$/', $page->uri()) > 0) {
        return $kirby->url() . '/content/' . $page->diruri() . '/' . $file->filename();
      } else {
        return $file->mediaurl();
      }
    }
]

The above will serve images that belong under an “album” subpage to be served directly from the content folder, but allow all other images on all other pages to be moved to the media folder as normal. However, my usecase for this was a site with 4 gigabytes of images (30,000+ images) and i did it for performance reasons rather than space concerns.

On a site the size you are talking, i would instead take other steps such is better image optimisation or using a hook to scale down excessivly larges images on upload (i do this on images over 2,000px wide). If you running Google Analytics on your site, you can use it to see the most common screen size people are looking at your site with. Use that to figure out the best max size for your images, but ill be surprised if its greater then 1920 x 1080.

There are tools out there that can recursively optimise images from the command line like image-optim if your on a mac.

Thank you very much for the above 2, I understand the benefits of the kirby 3 solution, but the plugin solution also gives me a choice!