question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LocalFiles image path contains 'public'

See original GitHub issue

Hi,

First of all I’d just like to say thanks for an amazing cms : )

After implementing the localFiles field type within my model the images do not correctly show within the admin ui.

The path to the images contains ‘public’ which obviously can’t be accessed frontend.

I’ve worked about this by adding this line above live 15 in keystone/templates/localfiles/form.jade

- value.path = value.path.replace('public/', '')

Is there a nicer way to solve this?

Thanks,

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
JedWatsoncommented, Dec 6, 2014

Sorry to take so long to get to this! it was a real headache, there were a lot of things to fix in the LocalFiles field type when I started digging into it, so that this wasn’t just a hacky fix.

I’ve brought the field implementation into line with the LocalFile type, and it now supports the same options of dest, prefix and format. This allows you to upload files to locations other than the public folder (which I personally would recommend) and still have them work correctly with public paths.

In my test project I have it working, including image previews, and it looks like this:

In keystone.js

Set add whatever path you’re uploading files to as one of your static paths, using an array:

keystone.set('static', ['public', 'files']);

In your Model

Specify the dest as the folder you want the uploads to go into, the same one you exposed with your static option. Set the prefix option to the public path of that directory, and if you’re using images, you can also set a format option to display thumbnails.

    localFile: {
        type: Types.LocalFile,
        dest: './files/single',
        prefix: '/single',
        format: function(item, file){
            return '<img src="' + file.href + '" style="max-width: 300px">'
        }
    },
    localFiles: {
        type: Types.LocalFiles,
        dest: './files/multiple',
        prefix: '/multiple',
        format: function(item, file){
            return '<img src="' + file.href + '" style="max-width: 300px">'
        }
    }

As you can see in the example, there’s also a new href property on the file inside the format funcition that gives access to the public href, it’s available on the List too.

For more details, check out the commit I did all this in.

If anything else isn’t working, please let me know, and I’ll sort it out.

0reactions
JedWatsoncommented, May 16, 2015

Thanks for pointing that out @tylkomat, I’ve fixed it and will push a new version soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can't I do <img src="C:/localfile.jpg">? - Stack Overflow
If we want to display images from local drive into our img tag of HTML page directly then we need to give relative...
Read more >
UOMF: Path-Independent Links to Local Files Via Locate
For linking to local files, I have already written about my tsfile: custom link method using Memacs. I use this for managing local...
Read more >
media - How to change the default images path and direct it to ...
After saving it, select Private local files served by Drupal as Default download method . ... in the public or private image directory....
Read more >
File target: add support for local file path as source - Drupal
I have a use case to import content with file url. ... I have the need to import local files too (around 50000...
Read more >
How to enable ability to input local image files in to node red ...
Then you need to change the value of httpStatic to be the full path to the folder containing your images. After you restart...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found