Hi, I''m using pages_cache in my image controller that displays images loaded from the DB. If I try to view a cached image, I get a dialog asking me if I want to download the image -- it doesn''t get displayed in the browser. I''m guessing this is a mime-type problem? I''m using lighttpd to serve. Anything special I need to do when caching images? Thanks, Joe
Anyone know? I''ve run the *nix command ''file'' on the cached pages (they''re saved with an .html extension) and they''re reported as jpeg. What''s weird is that when I go to /image/full/23 for the first time (image not cached), I can view the image in the browser. But when it''s cached and I go to that URL, it asks me to download it -- it doesn''t get displayed. On Apr 7, 2005 8:13 AM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m using pages_cache in my image controller that displays images > loaded from the DB. If I try to view a cached image, I get a dialog > asking me if I want to download the image -- it doesn''t get displayed > in the browser. > > I''m guessing this is a mime-type problem? I''m using lighttpd to > serve. Anything special I need to do when caching images? > > Thanks, > Joe >
Sorry - I don''t have an answer, but I have a couple of suggestions that might help. First, try ''curl --head http://myhost/image/full/23'' (using your real hostname) to see the headers returned from the request for the image. Compare the headers before and after the image is cached for a possible hint at what''s going on. You might need do something like @headers[''Content-Type''] = ''image/jpeg'' to change headers by hand in the controller.. Really not sure what the problem is, though... Second, there''s a nice description about how to get the client browsers to cache images (which you might want to do even if you cache them on your local file system): http://manuals.rubyonrails.com/read/chapter/62 Your server wouldn''t even get a request for the image from browsers with a cached copy, which would decrease bandwidth use, result in faster page loads for clients, and reduce server processing. Just a couple of ideas, and best of luck to you... Zach On Apr 7, 2005, at 4:15 PM, Joe Van Dyk wrote:> Anyone know? I''ve run the *nix command ''file'' on the cached pages > (they''re saved with an .html extension) and they''re reported as jpeg. > > What''s weird is that when I go to > > /image/full/23 > > for the first time (image not cached), I can view the image in the > browser. But when it''s cached and I go to that URL, it asks me to > download it -- it doesn''t get displayed. > > On Apr 7, 2005 8:13 AM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Hi, >> >> I''m using pages_cache in my image controller that displays images >> loaded from the DB. If I try to view a cached image, I get a dialog >> asking me if I want to download the image -- it doesn''t get displayed >> in the browser. >> >> I''m guessing this is a mime-type problem? I''m using lighttpd to >> serve. Anything special I need to do when caching images? >> >> Thanks, >> Joe >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >
I tried getting the headers... here''s what the results were. First time was an uncached image, second one was a cached filesystem image. As you can see, the content-type on the first one is a image/pjpeg. The second time, when it was being served from the file system, the content-type is application/octet-stream. Any ideas? $ curl --head http://jerrymahan.com/image/full/14 HTTP/1.1 200 OK Date: Fri, 08 Apr 2005 17:25:02 GMT Server: lighttpd/1.3.13 Content-Type: image/pjpeg Set-Cookie: _session_id=ae480760ff9aad8100fa83be29afb7b9; path=/ Last-Modified: Wed, 23 Mar 2005 18:06:09 GMT Content-Transfer-Encoding: binary Cache-Control: no-cache Content-Description: Probably a picture of a house X-Powered-By: The blood, sweat and tears of the fine, fine TextDrive staff Served-By: TextDrive $ curl --head http://jerrymahan.com/image/full/14 HTTP/1.1 200 OK Date: Fri, 08 Apr 2005 17:25:12 GMT Server: lighttpd/1.3.13 Last-Modified: Fri, 08 Apr 2005 17:25:03 GMT ETag: 661287914 Accept-Ranges: bytes Content-Type: application/octet-stream X-Powered-By: The blood, sweat and tears of the fine, fine TextDrive staff Served-By: TextDrive On Apr 7, 2005 9:51 PM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m doing both things you mentioned. > > Actually, looking at the mime-type when uploaded from windows and IE, > the mime-type is being recorded as image/jpeg\r or something like > that. It''s like there''s a carriage return at the end or something. > Might that be it? > > Joe > > On Apr 7, 2005 4:50 PM, Zach Thompson <zach-DZILUfagCPWukZHgTAicrQ@public.gmane.org> wrote: > > Sorry - I don''t have an answer, but I have a couple of suggestions that > > might help. > > > > First, try ''curl --head http://myhost/image/full/23'' (using your real > > hostname) to see the headers returned from the request for the image. > > Compare the headers before and after the image is cached for a possible > > hint at what''s going on. You might need do something like > > > > @headers[''Content-Type''] = ''image/jpeg'' > > > > to change headers by hand in the controller.. Really not sure what the > > problem is, though... > > > > Second, there''s a nice description about how to get the client browsers > > to cache images (which you might want to do even if you cache them on > > your local file system): > > > > http://manuals.rubyonrails.com/read/chapter/62 > > > > Your server wouldn''t even get a request for the image from browsers > > with a cached copy, which would decrease bandwidth use, result in > > faster page loads for clients, and reduce server processing. > > > > Just a couple of ideas, and best of luck to you... > > > > Zach > > > > On Apr 7, 2005, at 4:15 PM, Joe Van Dyk wrote: > > > > > Anyone know? I''ve run the *nix command ''file'' on the cached pages > > > (they''re saved with an .html extension) and they''re reported as jpeg. > > > > > > What''s weird is that when I go to > > > > > > /image/full/23 > > > > > > for the first time (image not cached), I can view the image in the > > > browser. But when it''s cached and I go to that URL, it asks me to > > > download it -- it doesn''t get displayed. > > > > > > On Apr 7, 2005 8:13 AM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> Hi, > > >> > > >> I''m using pages_cache in my image controller that displays images > > >> loaded from the DB. If I try to view a cached image, I get a dialog > > >> asking me if I want to download the image -- it doesn''t get displayed > > >> in the browser. > > >> > > >> I''m guessing this is a mime-type problem? I''m using lighttpd to > > >> serve. Anything special I need to do when caching images? > > >> > > >> Thanks, > > >> Joe > > >> > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > >
I think David''s got the right idea. Rails uses the extension specified for caching, unless one is in the URL. Maybe instead of just using caches_page, you can use the explcit version in the action: def full @image = Image.find(@params[''id'']) cache_page @image.content, "/image/full/#{@params[''id'']}.jpg'' ... rest of action ... end So basically you explicitly provide the content and where it should be cached to. Hope that helps, Ben On Apr 8, 2005 3:29 PM, David Morton <mortonda-0/IDydmJJnNeoWH0uzbU5w@public.gmane.org> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Joe Van Dyk wrote: > | I tried getting the headers... here''s what the results were. First > | time was an uncached image, second one was a cached filesystem image. > | As you can see, the content-type on the first one is a image/pjpeg. > | The second time, when it was being served from the file system, the > | content-type is application/octet-stream. > > If cached items are served by the filesystem, it is the job of the web > server to give the proper mime type. I bet what''s happening is that the > name on the filesystem doesn''t have an extension, and then the webserver > can''t guess the file type. What exactly is a file named "14" supposed > to be? (or whatever it is actually cached as) > > Can you rename your URL''s a little bit so that the extension stays the > same? http://jerrymahan.com/image/full/14.jpg > > - -- > David Morton > Maia Mailguard server side anti-spam/anti-virus solution: > http://www.maiamailguard.com > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.5 (GNU/Linux) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFCVvfASIxC85HZHLMRAtk+AJ9tVdNMYpNMgT6OGwcS7KbtgqD20gCfexnA > 3OgYfMXNLJLXtTSsj0cyCLI> =w+zJ > -----END PGP SIGNATURE----- > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Apr 8, 2005, at 2:29 PM, David Morton wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Joe Van Dyk wrote: > | I tried getting the headers... here''s what the results were. First > | time was an uncached image, second one was a cached filesystem image. > | As you can see, the content-type on the first one is a image/pjpeg. > | The second time, when it was being served from the file system, the > | content-type is application/octet-stream. > > If cached items are served by the filesystem, it is the job of the web > server to give the proper mime type. I bet what''s happening is that > the > name on the filesystem doesn''t have an extension, and then the > webserver > can''t guess the file type. What exactly is a file named "14" supposed > to be? (or whatever it is actually cached as) > > Can you rename your URL''s a little bit so that the extension stays the > same? http://jerrymahan.com/image/full/14.jpg >Check out the ActionController::Caching::Pages docs on http://api.rubyonrails.com/. It seems like this caching feature is designed for html, and saves with a .html extension by default. You could change the extension with Base.page_cache_extension, so the web server has a better chance to guess the mime type. Zach
On Apr 8, 2005 12:03 PM, Ben Schumacher <benschumacher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> def full > @image = Image.find(@params[''id'']) > cache_page @image.content, "/image/full/#{@params[''id'']}.jpg'' > ... rest of action ... > end > > So basically you explicitly provide the content and where it should be > cached to.Problem with that is, the webserver is configured to look for a .html file, and if it finds one, serve that, if not, pass the request off to rails to handle. If you try this, you''ll end up with a bunch of .jpg files in your public/ directory that will end up being completely ignored by rails and the webserver. -- Urban Artography http://artography.ath.cx
Would be easy enough to alter the .htaccess file to allow .jpg''s to match, too. On Apr 8, 2005 2:07 PM, Rob Park <rbpark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 8, 2005 12:03 PM, Ben Schumacher <benschumacher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > def full > > @image = Image.find(@params[''id'']) > > cache_page @image.content, "/image/full/#{@params[''id'']}.jpg'' > > ... rest of action ... > > end > > > > So basically you explicitly provide the content and where it should be > > cached to. > > Problem with that is, the webserver is configured to look for a .html > file, and if it finds one, serve that, if not, pass the request off to > rails to handle. If you try this, you''ll end up with a bunch of .jpg > files in your public/ directory that will end up being completely > ignored by rails and the webserver. > > -- > Urban Artography > http://artography.ath.cx >
On Apr 8, 2005 2:11 PM, Ben Schumacher <benschumacher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Would be easy enough to alter the .htaccess file to allow .jpg''s to match, too.Well, he''s on TextDrive so it''s lighttpd. There''s no .htaccess file and he''s at the mercy of his host to make this configuration change for him. The change is also more complicated than it sounds, because the way .html is handled is for a mod_rewrite rule to simply tack ".html" on to the end of _every_ request. Then if such a .html file exists, it is served and rails is never called. If it does not exist, the request is passed to rails directly with the .html still there, and rails knows to ignore the .html You can''t just do the same thing for .jpg, because then you''d be requesting URLs like "/image/full/23.html.jpg", the file doesn''t exist and rails doesn''t know what to do with that (eg, so everything breaks then). You might be able to do a _conditional_ mod_rewrite to say "only try .jpg if such a file actually exists", but I''m not sure that lighttpd can even do conditional mod_rewrite rules. -- Urban Artography http://artography.ath.cx
This is how I cache and store images and thumbnails in the database: Database: CREATE TABLE images ( id int(11) NOT NULL auto_increment, file_name varchar(255) NOT NULL, content_type varchar(255) NOT NULL, thumb blob NOT NULL, mid longblob NOT NULL, original longblob NOT NULL, PRIMARY KEY (id)); Controller Code: # Repeat this with changes for mid and orig. def thumb @image = Image.find_by_file_name(@params["filename"]) cache_page @image.thumb send_data @image.thumb, :filename => @image.file_name, :type => @image.content_type, :disposition => "inline" end Then I have a route that looks like this: map.connect ''/gallery/:gallery_name/thumb/:filename'', :controller=>"gallery", :action=>"thumb" Make sure your public dir is writeable by the web server. And it will create a dir structure like this: RAILS_ROOT/public/gallery/<gallery_name>/thumb/<filename> jim On Fri, 2005-04-08 at 14:20 -0600, Rob Park wrote:> On Apr 8, 2005 2:11 PM, Ben Schumacher <benschumacher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Would be easy enough to alter the .htaccess file to allow .jpg''s to match, too. > > Well, he''s on TextDrive so it''s lighttpd. There''s no .htaccess file > and he''s at the mercy of his host to make this configuration change > for him. > > The change is also more complicated than it sounds, because the way > .html is handled is for a mod_rewrite rule to simply tack ".html" on > to the end of _every_ request. Then if such a .html file exists, it is > served and rails is never called. If it does not exist, the request is > passed to rails directly with the .html still there, and rails knows > to ignore the .html > > You can''t just do the same thing for .jpg, because then you''d be > requesting URLs like "/image/full/23.html.jpg", the file doesn''t exist > and rails doesn''t know what to do with that (eg, so everything breaks > then). You might be able to do a _conditional_ mod_rewrite to say > "only try .jpg if such a file actually exists", but I''m not sure that > lighttpd can even do conditional mod_rewrite rules. >-- jim <jim-rhf1kIDhBaeB8E1WFlbJj6xOck334EZe@public.gmane.org>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Joe Van Dyk wrote: | I tried getting the headers... here''s what the results were. First | time was an uncached image, second one was a cached filesystem image. | As you can see, the content-type on the first one is a image/pjpeg. | The second time, when it was being served from the file system, the | content-type is application/octet-stream. If cached items are served by the filesystem, it is the job of the web server to give the proper mime type. I bet what''s happening is that the name on the filesystem doesn''t have an extension, and then the webserver can''t guess the file type. What exactly is a file named "14" supposed to be? (or whatever it is actually cached as) Can you rename your URL''s a little bit so that the extension stays the same? http://jerrymahan.com/image/full/14.jpg - -- David Morton Maia Mailguard server side anti-spam/anti-virus solution: http://www.maiamailguard.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCVvfASIxC85HZHLMRAtk+AJ9tVdNMYpNMgT6OGwcS7KbtgqD20gCfexnA 3OgYfMXNLJLXtTSsj0cyCLI=w+zJ -----END PGP SIGNATURE-----
On Apr 8, 2005 1:20 PM, Rob Park <rbpark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 8, 2005 2:11 PM, Ben Schumacher <benschumacher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Would be easy enough to alter the .htaccess file to allow .jpg''s to match, too. > > Well, he''s on TextDrive so it''s lighttpd. There''s no .htaccess file > and he''s at the mercy of his host to make this configuration change > for him. > > The change is also more complicated than it sounds, because the way > .html is handled is for a mod_rewrite rule to simply tack ".html" on > to the end of _every_ request. Then if such a .html file exists, it is > served and rails is never called. If it does not exist, the request is > passed to rails directly with the .html still there, and rails knows > to ignore the .html > > You can''t just do the same thing for .jpg, because then you''d be > requesting URLs like "/image/full/23.html.jpg", the file doesn''t exist > and rails doesn''t know what to do with that (eg, so everything breaks > then). You might be able to do a _conditional_ mod_rewrite to say > "only try .jpg if such a file actually exists", but I''m not sure that > lighttpd can even do conditional mod_rewrite rules.Hm. So, what do I do now? Could I have /image/thumbnail/14.jpg, where 14 is the id of the image (and ignore the .jpg extension)?
Sure, that''d probably work. I''m still not sure why the solution Jim and/or I propose wouldn''t work. You could just do what I suggested and simply not depend on the web server (although I still this it''d work) and just add the smarts into your action (like Jim''s suggestion): def full if File.exists?("#{RAILS_ROOT}/public/image/full/#{@params[''id'']}.jpg") send_file "#{RAILS_ROOT}/public/image/full/#{@params[''id'']}.jpg", :filename => @image.file_name, :type => @image.content_type, :disposition => "inline" else @image = Image.find(@params[''id'']) cache_page @image.content, "/image/full/#{@params[''id'']}.jpg" ... rest of action ... end end That outta work no matter what the web server is. And while it still requires a small amount of Rails interaction, it''s still significantly less database usage. Cheers, Ben On Apr 8, 2005 4:45 PM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 8, 2005 1:20 PM, Rob Park <rbpark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On Apr 8, 2005 2:11 PM, Ben Schumacher <benschumacher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Would be easy enough to alter the .htaccess file to allow .jpg''s to match, too. > > > > Well, he''s on TextDrive so it''s lighttpd. There''s no .htaccess file > > and he''s at the mercy of his host to make this configuration change > > for him. > > > > The change is also more complicated than it sounds, because the way > > .html is handled is for a mod_rewrite rule to simply tack ".html" on > > to the end of _every_ request. Then if such a .html file exists, it is > > served and rails is never called. If it does not exist, the request is > > passed to rails directly with the .html still there, and rails knows > > to ignore the .html > > > > You can''t just do the same thing for .jpg, because then you''d be > > requesting URLs like "/image/full/23.html.jpg", the file doesn''t exist > > and rails doesn''t know what to do with that (eg, so everything breaks > > then). You might be able to do a _conditional_ mod_rewrite to say > > "only try .jpg if such a file actually exists", but I''m not sure that > > lighttpd can even do conditional mod_rewrite rules. > > Hm. So, what do I do now? > > Could I have /image/thumbnail/14.jpg, where 14 is the id of the image > (and ignore the .jpg extension)? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I guess that might work. And it''ll probably be fast enough (I hope). On Apr 8, 2005 3:54 PM, Ben Schumacher <benschumacher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sure, that''d probably work. I''m still not sure why the solution Jim > and/or I propose wouldn''t work. You could just do what I suggested and > simply not depend on the web server (although I still this it''d work) > and just add the smarts into your action (like Jim''s suggestion): > > def full > if File.exists?("#{RAILS_ROOT}/public/image/full/#{@params[''id'']}.jpg") > send_file "#{RAILS_ROOT}/public/image/full/#{@params[''id'']}.jpg", > :filename => @image.file_name, > :type => @image.content_type, > :disposition => "inline" > else > @image = Image.find(@params[''id'']) > cache_page @image.content, "/image/full/#{@params[''id'']}.jpg" > ... rest of action ... > end > end > > That outta work no matter what the web server is. And while it still > requires a small amount of Rails interaction, it''s still significantly > less database usage. > > Cheers, > > Ben > On Apr 8, 2005 4:45 PM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On Apr 8, 2005 1:20 PM, Rob Park <rbpark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Apr 8, 2005 2:11 PM, Ben Schumacher <benschumacher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Would be easy enough to alter the .htaccess file to allow .jpg''s to match, too. > > > > > > Well, he''s on TextDrive so it''s lighttpd. There''s no .htaccess file > > > and he''s at the mercy of his host to make this configuration change > > > for him. > > > > > > The change is also more complicated than it sounds, because the way > > > .html is handled is for a mod_rewrite rule to simply tack ".html" on > > > to the end of _every_ request. Then if such a .html file exists, it is > > > served and rails is never called. If it does not exist, the request is > > > passed to rails directly with the .html still there, and rails knows > > > to ignore the .html > > > > > > You can''t just do the same thing for .jpg, because then you''d be > > > requesting URLs like "/image/full/23.html.jpg", the file doesn''t exist > > > and rails doesn''t know what to do with that (eg, so everything breaks > > > then). You might be able to do a _conditional_ mod_rewrite to say > > > "only try .jpg if such a file actually exists", but I''m not sure that > > > lighttpd can even do conditional mod_rewrite rules. > > > > Hm. So, what do I do now? > > > > Could I have /image/thumbnail/14.jpg, where 14 is the id of the image > > (and ignore the .jpg extension)? > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
caches_page dumps the file into the file system. Just use routes to give the file a better url like /image/full/23/rainbow.jpg this will cause it to be stored with a .jpg ending so that the web server can figure out the correct mime type on its own. -- Tobi http://www.snowdevil.ca - Snowboards that don''t suck http://www.hieraki.org - Open source book authoring http://blog.leetsoft.com - Technical weblog
joevd@bidwell:~/sites/bestnewhome/trunk/public$ curl --head http://bestnewhome.textdriven.com/image/full/14/something.jpg HTTP/1.1 200 OK Date: Sat, 09 Apr 2005 06:14:56 GMT Server: lighttpd/1.3.13 Last-Modified: Sat, 09 Apr 2005 06:14:43 GMT ETag: 1803197331 Accept-Ranges: bytes Content-Type: application/octet-stream X-Powered-By: The blood, sweat and tears of the fine, fine TextDrive staff Served-By: TextDrive joevd@bidwell:~/sites/bestnewhome/trunk/public$ curl --head http://bestnewhome.textdriven.com/image/full/14/something.jpg HTTP/1.1 200 OK Date: Sat, 09 Apr 2005 06:15:07 GMT Server: lighttpd/1.3.13 Last-Modified: Sat, 09 Apr 2005 06:14:43 GMT ETag: 1803197331 Accept-Ranges: bytes Content-Type: application/octet-stream X-Powered-By: The blood, sweat and tears of the fine, fine TextDrive staff Served-By: TextDrive On Apr 8, 2005 5:40 PM, Tobias Luetke <tobias.luetke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> caches_page dumps the file into the file system. Just use routes to > give the file a better url like /image/full/23/rainbow.jpg this will > cause it to be stored with a .jpg ending so that the web server can > figure out the correct mime type on its own. > > -- > Tobi > http://www.snowdevil.ca - Snowboards that don''t suck > http://www.hieraki.org - Open source book authoring > http://blog.leetsoft.com - Technical weblog >
(So, as you can see, having a jpeg extension at the end didn''t seem to solve the problem) On Apr 8, 2005 11:17 PM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> joevd@bidwell:~/sites/bestnewhome/trunk/public$ curl --head > http://bestnewhome.textdriven.com/image/full/14/something.jpg > HTTP/1.1 200 OK > Date: Sat, 09 Apr 2005 06:14:56 GMT > Server: lighttpd/1.3.13 > Last-Modified: Sat, 09 Apr 2005 06:14:43 GMT > ETag: 1803197331 > Accept-Ranges: bytes > Content-Type: application/octet-stream > X-Powered-By: The blood, sweat and tears of the fine, fine TextDrive staff > Served-By: TextDrive > > joevd@bidwell:~/sites/bestnewhome/trunk/public$ curl --head > http://bestnewhome.textdriven.com/image/full/14/something.jpg > HTTP/1.1 200 OK > Date: Sat, 09 Apr 2005 06:15:07 GMT > Server: lighttpd/1.3.13 > Last-Modified: Sat, 09 Apr 2005 06:14:43 GMT > ETag: 1803197331 > Accept-Ranges: bytes > Content-Type: application/octet-stream > X-Powered-By: The blood, sweat and tears of the fine, fine TextDrive staff > Served-By: TextDrive > > On Apr 8, 2005 5:40 PM, Tobias Luetke <tobias.luetke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > caches_page dumps the file into the file system. Just use routes to > > give the file a better url like /image/full/23/rainbow.jpg this will > > cause it to be stored with a .jpg ending so that the web server can > > figure out the correct mime type on its own. > > > > -- > > Tobi > > http://www.snowdevil.ca - Snowboards that don''t suck > > http://www.hieraki.org - Open source book authoring > > http://blog.leetsoft.com - Technical weblog > > >
Aha. On further investation, lighttpd is serving all images, even static ones, as ''application/octet-stream''. So it doesn''t seem like this is a rails issue anymore, but i''d still like some help! :-) On Apr 8, 2005 11:21 PM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> (So, as you can see, having a jpeg extension at the end didn''t seem to > solve the problem) > > On Apr 8, 2005 11:17 PM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > joevd@bidwell:~/sites/bestnewhome/trunk/public$ curl --head > > http://bestnewhome.textdriven.com/image/full/14/something.jpg > > HTTP/1.1 200 OK > > Date: Sat, 09 Apr 2005 06:14:56 GMT > > Server: lighttpd/1.3.13 > > Last-Modified: Sat, 09 Apr 2005 06:14:43 GMT > > ETag: 1803197331 > > Accept-Ranges: bytes > > Content-Type: application/octet-stream > > X-Powered-By: The blood, sweat and tears of the fine, fine TextDrive staff > > Served-By: TextDrive > > > > joevd@bidwell:~/sites/bestnewhome/trunk/public$ curl --head > > http://bestnewhome.textdriven.com/image/full/14/something.jpg > > HTTP/1.1 200 OK > > Date: Sat, 09 Apr 2005 06:15:07 GMT > > Server: lighttpd/1.3.13 > > Last-Modified: Sat, 09 Apr 2005 06:14:43 GMT > > ETag: 1803197331 > > Accept-Ranges: bytes > > Content-Type: application/octet-stream > > X-Powered-By: The blood, sweat and tears of the fine, fine TextDrive staff > > Served-By: TextDrive > > > > On Apr 8, 2005 5:40 PM, Tobias Luetke <tobias.luetke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > caches_page dumps the file into the file system. Just use routes to > > > give the file a better url like /image/full/23/rainbow.jpg this will > > > cause it to be stored with a .jpg ending so that the web server can > > > figure out the correct mime type on its own. > > > > > > -- > > > Tobi > > > http://www.snowdevil.ca - Snowboards that don''t suck > > > http://www.hieraki.org - Open source book authoring > > > http://blog.leetsoft.com - Technical weblog > > > > > >
On Apr 9, 2005 12:24 AM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Aha. On further investation, lighttpd is serving all images, even > static ones, as ''application/octet-stream''. So it doesn''t seem like > this is a rails issue anymore, but i''d still like some help! :-)It''s a lighttpd issue. You have to change your lighttpd config to send the right mimetype for .jpg files now. Lighttpd is very stupid when it comes to mimetypes, it doesn''t use any mimetype magic like apache does, it just sets the mimetype based on file extension, but even then it requires the admin to explcitly define WHICH mimetype is for each file. For example, I have this is my lighttpd config: mimetype.assign = ( ".gif" => "image/gif", ".png" => "image/png", ".jpg" => "image/jpeg", ".jpeg" => "image/jpeg", ".html" => "text/html", ".shtml" => "text/html", ".txt" => "text/plain", ".css" => "text/css", ".gpg" => "application/pgp-keys" ) Again, this change can only be made in your lighttpd.conf file, so you''ll have to ask TextDrive support to do this to your setup. -- Urban Artography http://artography.ath.cx
On 9.4.2005, at 11:52, Rob Park wrote:> On Apr 9, 2005 12:24 AM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Aha. On further investation, lighttpd is serving all images, even >> static ones, as ''application/octet-stream''. So it doesn''t seem like >> this is a rails issue anymore, but i''d still like some help! :-) > > It''s a lighttpd issue. You have to change your lighttpd config to send > the right mimetype for .jpg files now. Lighttpd is very stupid when it > comes to mimetypes, it doesn''t use any mimetype magic like apache > does, it just sets the mimetype based on file extension, but even then > it requires the admin to explcitly define WHICH mimetype is for each > file. For example, I have this is my lighttpd config: > > mimetype.assign = ( > ".gif" => "image/gif", > ".png" => "image/png", > ".jpg" => "image/jpeg", > ".jpeg" => "image/jpeg", > ".html" => "text/html", > ".shtml" => "text/html", > ".txt" => "text/plain", > ".css" => "text/css", > ".gpg" => "application/pgp-keys" > ) > > Again, this change can only be made in your lighttpd.conf file, so > you''ll have to ask TextDrive support to do this to your setup.Why''s that? You (or I, at least) run your own lighttpd on textdrive, so you can use whatever config file you want to. You start the process yourself and can thus modify the config file to your heart''s content. AFAIK the only thing with lighttpd on TxD that needs a ticket is getting a high port open for the server. After that you can go to Webmin and point your domain (or subdomain) to that port. I got some help from people on irc while doing this, but at least theoretically there''s no need for an admin to interfere after the port has been opened. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Apr 7, 2005 8:13 AM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m using pages_cache in my image controller that displays images > loaded from the DB. If I try to view a cached image, I get a dialog > asking me if I want to download the image -- it doesn''t get displayed > in the browser. > > I''m guessing this is a mime-type problem? I''m using lighttpd to > serve. Anything special I need to do when caching images? > > Thanks, > JoePROBLEM SOLVED I had to do two things. 1) Add mime-type mappings to lighttpd''s config file. Apparently, it''s not magic like Apache. 2) I should''ve done this earlier, but I created a couple helper functions that would return image tags and links. The image tag helpers append the appropriate file extension to the url for the image (which the image code promptly ignores, but it''s necessary for lighttpd caching. My application helper looks like this: # The methods added to this helper will be available to all templates in the application. module ApplicationHelper # Use when you want to display a html link that has an image that leads to a # different size version of the image def image_click_tag(initial_size, link_size, id) img_tag = image_tag(initial_size, id) url = image_url(link_size, id) "<a href = ''#{url}''>#{img_tag}</a>" end # Returns an array that contain the ID of three random images # that have been specified to be displayed on the main pages. def random_image_array(size = 3) random_images = Image.find_by_sql("select id from images where house_id != ''0'' and display_main = ''1'' order by random() limit 3") random_images.sort_by{rand}.to_a end # Given a size and an id, returns a html image tag def image_tag(size, id, alt = ''an image'') img_url = image_url(size, id) "<img src = ''#{img_url}'' alt = ''#{alt}''>" end # Given a size (thumbnail, medium, etc) and an id, return the URL for the image. # Look at the image mime-type to determine what file extension should be added # to the image. The file extension is used only for caching purposes -- the # image code (as of now) ignores the file extension. def image_url(size, id) mime_to_file_extension = { "image/pjpeg" => ".jpg", "image/jpeg" => ".jpg", "image/png" => ".png", "image/gif" => ".gif" } image = Image.find(id) extension = mime_to_file_extension[image.mime.strip] url_for :controller => "image", :action => size, :id => "#{id}#{extension}" end end