1

I'm having some trouble getting started with Craft.

I'm attempting to upload some image assets for the first time.

I've set up an asset source. I've tried using both a relative and an absolute path to the file. I am certain that the absolute path name is correct because I simply copied from the pwd command on my server. Also, when I look in the directory, I see the uploaded images.

I've also supplied a url for the source. (I've actually tried a few different ones.)

Every time I've made a change, I've gone into settings and run Update Asset Indexes just to be sure everything was up to date.

However, when I try to view the images, I get a 404. I've tried typing the URL into the address bar, as well as clicking on "View asset" on the assets page.

I did see this similar question, but I'm not running an nginx server. I'm running Apache.

I would love any insight on what I could be doing wrong. If you need any additional information, I'll be more than happy to edit it in.

Edit: For clarity, I'm trying to set up my file directory and my url to have different structures, which I believe is possible. For example, I want my images to be in public_html/media/images, but I want the url for images to be http://mysite.com/images. Doing that seems to be what causes the problem.

  • Check your folder permissions, Craft was creating folders for assets with an obscure permission on my server which was saving but was unable to be called by apache. – William Isted Jan 19 '16 at 12:11
  • @WilliamIsted I did that. They're all owned by www-data, have read permissions across the board, and write permissions for the owner and group. – jimchristie Jan 20 '16 at 2:50
2

I'll use myself as an example, so if something isn't right we'll know who to blame.

First thing I do is set up an environment variable in my craft/config/general.php file like this:

...
'.dev' => array(
    'devMode' => true,
    'siteUrl' => 'http://mysite.dev/',
    'environmentVariables' => array(
        'basePath' => $_SERVER['DOCUMENT_ROOT'] . '/',
        'baseUrl' => 'http://mysite.dev/',
    )
)
...

Then, when I am creating assets sources, I'll create a general "Images" source:

Name: Images
Handle: images
File System Path: {basePath}media/images/
URL: /media/images/

Note that I am using my environment variable in the file system path.

{basePath}

You can call that whatever you want, it just has to match.

So if you were to view the source of my site, an image that was uploaded would have the path of:

http://www.mysite.com/media/images/my-image.jpg

Hope this helps!

|improve this answer|||||
  • Setting it up like this works for me whether or not I use environment variables. The problem comes when I try to make the url differ from the file system path, which I thought was possible in Craft. For example, I want to store my images in {basePath}media/images, but show them at www.mysite/images. Whenever I try to do that, I get a 404. – jimchristie Jan 19 '16 at 2:09
0

For example, I want my images to be in public_html/media/images, but I want the url for images to be http://mysite.com/images.

When you configure an asset source you tell Craft where to find the images, not where you want them to be.

|improve this answer|||||
  • I'm not sure exactly what you're suggesting the problem is. I set my File system path to public_html/media/images. The images upload just fine, which I've verified by navigating to that directory on the server. They just don't display when clicking on "view asset" on the assets page. Instead, I get a 404. – jimchristie Jan 20 '16 at 2:55
  • You have to set the URL to /media/images/ because that's the path to the folder. I was just saying you have to type in the facts, not your wishes (if that makes sense). – carlcs Jan 20 '16 at 7:24
  • It was my understanding that you didn't have to use the same path in the URL as the path to the folder. I thought that's why there were two separate fields for path to file and path to folder. Is that not correct? – jimchristie Jan 22 '16 at 21:10
  • 1
    No, both have to be set according to the path "public root" to asset directory. There's two separate fields because sometimes you need to set one or both of them as absolute paths and relative paths do not work. – carlcs Jan 22 '16 at 23:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.