Linking to uploaded files

Here's a little piece of trivia for all those who don't read the documentation (which, in reality, is almost everybody): you don't need to know the URL of a post to link to a file uploaded to it. LnBlog takes care of that for you.

How does this work? Well, for files uploaded to a post, it's actually quite easy. When you give the link URL, only specify the name of the file. No path, no domain, just the file name. When you submit the post and view it in your browser, you'll see that the link displays the absolute URI of the file. Basically, when your post is displayed, whether in a browser or RSS feed, LnBlog will scan it for links and image references and convert any bare file name (meaning a relative URL with no slashes in it) into an absolute URI based on the URI of the post.

The handy thing about this is that it's so transparent. This conversion works automatically in both HTML and LBCode markup modes and is done on the href attributes of anchor (<a>) tags and the src attributes of image tags. It works very nicely with the new feature in version 0.7.1 that lets you upload files at the same time you make the post. All you need to do is give the file name and the URI calculation is done for you.

This feature was originally added because I was sick of making a post, uploading my files, and then editing the post because I didn't know the full URI of the files until after the post was submitted. I had to do that because LnBlog bases the URI of a post, and hence the path where its files are stored, on the date and time at which it was made.

Of course, I could have just made a single upload directory and put all my files there, but I didn't really like that idea. I wanted to keep things more "semantic" than that. For some files, like releases of LnBlog, it makes sense to put them in a central directory at or near the blog root. However, some files really are only related to one particular post. To me, it makes sense to keep those files with the post they're meant for. And so I decided to take the guess work out of figuring out the URI for that post.

You can reply to this entry by leaving a comment below. This entry accepts Pingbacks from other blogs.

Add your comments #

A comment body is required. No HTML code allowed. URLs starting with http:// or ftp:// will be automatically converted to hyperlinks.