Forum How do I...?

Reference Local Images

daneren2005
I am currently doing some processing of images, saving them to S3, then changing the url to point to that S3 url. This is obviously a waste of bandwidth, but I'm not sure if Prince can reference a local file url. If I have a <img src="/tmp/myfile.png">, will Prince grab the file from the filesystem fine?
daneren2005
I also need to make sure that it works from within SVG <image href="/tmp/myfile.png">
mikeday
Yes, local images are fine unless you have specified --no-local-files. Are the HTML/SVG documents also local files?
daneren2005
The SVG is embedded in the HTML passed to Prince, so yes it is local.
mikeday
I mean it's being passed via stream or local file, not a remote HTTP URL.
daneren2005
The html is being passed as a stream: $prince->convert_string_to_file($html, $file_to_save, $msg). I tried both <img src="/tmp/myfile.png"> and <img src="//tmp/myfile.png"> and both did not load correctly:

https://example.com/tmp/yearbook/f440f726-55c7-49f2-b5aa-69e8fdb86dd8.png: warning: The requested URL returned error: 500 Internal Server Error
https://tmp/yearbook/51dde8e4-4ab7-418b-a3e7-cd91b5f1c512.png: warning: Could not resolve host: tmp

I am not setting --no-local-files (in fact, I don't see it as a option under http://www.princexml.com/doc/command-line/). Is there something else that might be interfering with the syntax I am passing in? Is there some other prefix I need to let the parser know it is not a url? I am setting a base url with $prince->setBaseURL('https://example.com').

Edited by daneren2005

mikeday
Are you specifying --baseurl? If that is the case, then paths like /tmp will be interpreted relative to the base URL. Also, in paths with a double slash like //tmp/foo, the tmp is interpreted as the server name.

If the document has a HTTP base URL you will need to make the local file paths use an explicit file: scheme, like file:///tmp/myfile.png
daneren2005
Yes I am setting --baseurl. Prepending file:// fixed it. Thank you for the help.