background-image path issue

asked 2014-07-28 17:14:02 +0800

clueless gravatar image clueless
62 1 4

I want to store all images in a centralized directory that is outside my application, including the possibility of a different drive.

I am dynamically creating the file URL based on a configuration setting concatenated with the image to display. I know this code works based on the fact that if I set the path to my images relative to the application all is well, however when I set the path to the image outside of the application the image is never displayed. 1. the external path is correctly pointing to the right directory and is read from the configuration entry correctly. 2. the image file with extension is identified in the code correctly and is physically where the external path is pointing to. 3. The O/S is Win 7 and there are no permission errors for accessing the file. 4. there are no errors or exceptions thrown

what works: background-image: url('../myapp/images/foo.png');

what does not work: background-image: url('e:/myapp/images/foo.png'); background-image: url('e:\myapp\images\foo.png'); background-image: url('e:\myapp\images\foo.png'); background-image: url("e:"+File.separator+"myapp"+... you get the idea I hope

when I use Chrome to inspect the field I see background-image: url(file:///e:/myapp/images/foo.png); <-- in other words, file:/// pre-appended to my entries above.

I noticed a similar question in these forums: http://forum.zkoss.org/question/92875/background-image-path-to-external-url/

though in that case they are going to an external http location and I am going to an external, reachable file location.

The comment by Chill does not directly answer the issue that we both seem to be experiencing: file locations outside the applications relative path do not seem to work, or we are doing something wrong to get to the path.

thanks for your help Cosmic

delete flag offensive retag edit

2 Answers

Sort by » oldest newest most voted

answered 2014-07-28 18:32:07 +0800

chillworld gravatar image chillworld flag of Belgium
5337 4 9

updated 2014-07-29 04:29:56 +0800

Hi Clueless,

The comment I placed was to point out a bad practice, that's why it's a comment and no answer. If you don't do the bad practice you don't have that problem.

If you still sure you want it like that, then you should watch this fiddle created for you.

Edit :

Create c:/test.jpg.
Run this fiddle.

That requirment is logic, you have to save it to a fileshare somewhere.
Hope that this can help you out.

Greetz chill.

link publish delete flag offensive edit

answered 2014-07-28 19:07:33 +0800

clueless gravatar image clueless
62 1 4

thank you for your response. As my post indicates, it is the external file location that is giving me trouble, have you ever tried or had success using file:///?

FYI, I am deploying an application that allows customers to upload their own images in a clustered environment. We have a drive that swings with the active cluster. Having an external drive, separate from the application, makes practical sense to me.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2014-07-28 17:14:02 +0800

Seen: 19 times

Last updated: Jul 29 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More