0

I am new to Craft 3 and I have seen similar questions asked many but never answered.

I want to store my images in a directory that is not public, yet I want them to be served correctly by Craft. The reason why I am doing this is that I work with shared disks for EC2 instances in AWS (Not S3) so I need to be able to mount shared volumes to store images for all the Front Ends to serve.

I am experimenting (without mounting a disk, to simplify) and I have a volume with:

name: images
handle: images
Assets in this volume have public URLs: on
Base URL: @web/somestuff
Volume Type: local folder
File System Path: /var/www/mydomain.com/imagesrepo

Note that the directory /var/www/mydomain.com/imagesrepo has 777 rights, images are uploaded correctly in the CMS, and even "image transform" correctly creates subdirectories and resizes images. I see the images thumbnails but, following the problem explained below, the image shows a broken when I click on "preview".

Also note that in the directory tree, imagesrepo is outside the website root, at the same level with the "web", "config", etc... directories for Craft. (/var/www/mydomain.com/web is the website root)

I have installed "element api" and I am getting the URL of the image with

$img->getUrl(),

and a "resized" version with

$img->getUrl('largepic').

The result URLs I am getting are

https://mydomain.com/somestuff/2013-12-22-23.46.18.jpg
https://mydomain.com/somestuff/_largepic/2013-12-22-23.46.18.jpg

The URLs look correctly built and I would expect that, once called, Craft would fetch the image file with the actual disk location in /var/www/mydomain.com/imagesrepo and read it out to the front end. Instead I get a 404 page with

HTTP 404 – Not Found – yii\web\NotFoundHttpException

and the whole stack trace, as if Craft was trying to find "somestuff" as a regular template.

Am I doing something wrong or is Craft not able to store assets in a physical location and serve them from a logical one?

P.s. Please do not tell me that there are drivers and plugins for AWS solutions. There are many reasons to store assets in physical locations that differ from the URL

  • is the switch on the asset's volume set to "Assets in this volume have public URLs"? – Matthias Apr 6 at 21:11
  • Yes. I listed all attributes in the first code snippet box in my question. – Marco Camurri Apr 7 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.