Absolute image links

#1

Hi, is it possible when uploading images to have them upload into the webroot and to use an absolute address instead of relative?

0 Likes

#2

@remotebox Of course, you’re welcome to put images anywhere in the www folder, and reference them relatively or absolutely.

0 Likes

#3

I was hoping there would be a way using the image upload functionality.
The reasoning behind this is that I am using the software to allow users to build pages of which the html generated code can then be inserted into their corporate site. By using absolute links to the uploaded images it means the users don’t then have the issue of copying images and editing code.

0 Likes

#4

Ah, I see what you mean now—I misunderstood before. Vapid does render uploaded images as absolute paths (e.g. <img src="/uploads/uploaded_image.jpg">), however it doesn’t prepend the host name (e.g. <img src="http://example.com/uploads/uploaded_image.jpg">), nor would it be able to place the images in the root directory.

If you’re allowing using to copy/paste the generated code from the public site (i.e., not the dashboard), you might be able to solve the problem by prepending the hostname with JavaScript.

var imgs = document.querySelectorAll('[src^="/uploads"]');

[].forEach.call(imgs, function(img) {
  // Will prepend the current hostname
  img.src = img.src;
});
0 Likes

#5

Aha! That’s perfect!!

Thank you for your help :slight_smile:

1 Like