Professional Web Applications Themes

Question graphics output of CGIs (mime-type issue?) - Ruby

What's the proper way to deliver a grpahical file via HTTP? For example, supposing a web page has a bit of HTML like: <img src="http://foo.com/cgi-bin/myprog.cgi"> Then how should myprog.cgi deliver its output? Is there direct support for this in one of the libraries, or do you just have to know how to do it? I tried just using a Content-type of image/jpeg, but I got garbage in the browser. Thanks, Hal -- Hal Fulton [email]hal9000hypermetrics.com[/email]...

  1. #1

    Default Question re: graphics output of CGIs (mime-type issue?)

    What's the proper way to deliver a grpahical
    file via HTTP?

    For example, supposing a web page has a bit of
    HTML like:

    <img src="http://foo.com/cgi-bin/myprog.cgi">

    Then how should myprog.cgi deliver its output?
    Is there direct support for this in one of the
    libraries, or do you just have to know how to
    do it?

    I tried just using a Content-type of image/jpeg,
    but I got garbage in the browser.

    Thanks,
    Hal

    --
    Hal Fulton
    [email]hal9000hypermetrics.com[/email]


    Hal E. Fulton Guest

  2. #2

    Default Re: Question re: graphics output of CGIs (mime-type issue?)

    * Hal E. Fulton <hal9000hypermetrics.com> [0728 01:28]:
    > What's the proper way to deliver a grpahical
    > file via HTTP?
    >
    > For example, supposing a web page has a bit of
    > HTML like:
    >
    > <img src="http://foo.com/cgi-bin/myprog.cgi">
    >
    > Then how should myprog.cgi deliver its output?
    > Is there direct support for this in one of the
    > libraries, or do you just have to know how to
    > do it?
    >
    > I tried just using a Content-type of image/jpeg,
    > but I got garbage in the browser.
    Don't some browsers insist on looking at filetype
    rather than mime-type?

    Two workarounds spring to mind (I've installed Ruby-GD for this
    very reason, but haven't tried yet):

    Would this work?
    #(Apache,mod_ruby)

    <Directory /docroot/genimg/ >
    <FilesMatch ".jpg">
    Options +ExecCGI
    SetHandler ruby-object
    RubyHandler Apache::RubyRun.instance
    </FilesMatch>
    </Directory>

    Or alternatively (and haven't figured out how to do this yet)

    map all requests to a particular location to your cgi
    (i.e. requests to [url]http://yourserver.com/edit-img/[/url]
    are mapped to [url]http://yourserver.com/cgi-bin/image.cgi[/url]
    )
    then use the trailing path_info to identify what kind of inmage to create:

    so

    [url]http://yourserver.com/edit-img/greyscale/images/foo.gif[/url]

    will return a greyscale version of [url]http://yourserver.com/images/foo.gif[/url],

    [url]http://yourserver.com/edit-img/resize/80-200/images/foo.gif[/url]

    does the obvious,etc.

    This is handy for existing images you need to manipulate, obviously.


    --
    As the trials of life continue to take their toll, remember that there
    is always a future in Computer Maintenance.
    -- National Lampoon, "Deteriorata"
    Rasputin :: Jack of All Trades - Master of Nuns

    Rasputin Guest

  3. #3

    Default Re: Question re: graphics output of CGIs (mime-type issue?)

    * Brian Candler <B.Candlerpobox.com> [0745 11:45]:
    > On Fri, Jul 18, 2003 at 07:28:42PM +0900, Rasputin wrote:
    > > > I tried just using a Content-type of image/jpeg,
    > > > but I got garbage in the browser.
    > >
    > > Don't some browsers insist on looking at filetype
    > > rather than mime-type?
    >
    > What do you mean by "filetype"? Do you mean "extension"? It shouldn't make
    > any different. If the server sends back
    >
    > Content-type: image/jpeg
    >
    > then where is the filename to be found in the response? The browser could
    > look at the source URL (/foo/bar/baz.cgi) but that doesn't tell it anything
    > about the type of the response.
    I'm talking about the extension.
    And some versions of IE. So laws of logic don't apply :)
    > ScriptAlias "/edit-img" "/usr/local/apache/cgi-bin/image.cgi"
    >
    > ought to do the trick.
    Doh! Cheers, will try that.
    --
    A successful [software] tool is one that was used to do something
    undreamed of by its author.
    -- S. C. Johnson
    Rasputin :: Jack of All Trades - Master of Nuns

    Rasputin Guest

  4. #4

    Default Re: Question re: graphics output of CGIs (mime-type issue?)

    Hal E. Fulton wrote:
    > What's the proper way to deliver a grpahical
    > file via HTTP?
    with mod_ruby:
    image is an object with such methods:
    image.mime-type -> image/jpeg, image/png, image/gif - depending on image
    image.content -> binary content of picture

    picture.rbx
    ---
    image = Image.new( filename )

    r = Apache.request

    r.content_type = image.mime_type
    r.headers_out['Accept-Ranges'] = 'bytes'
    r.headers_out['Content-Length'] = image.content.size.to_s

    r.send_http_header

    print image.content
    ---


    --
    Andrey Kulinich
    IT Group
    Software developer
    Phone/Fax +380 (372) 58-43-10
    e-mail: [email]Andrey.Kulinichitgrp.net[/email]
    [url]http://www.itgrp.net[/url]


    Andrew Kulinich Guest

Similar Threads

  1. How to log the output of Mime::Lite ?
    By kenhensleys@yahoo.com in forum PERL Modules
    Replies: 1
    Last Post: June 27th, 01:13 AM
  2. MIME type for .dat
    By dwd1 in forum Macromedia ColdFusion
    Replies: 0
    Last Post: March 25th, 03:56 PM
  3. Mime Type for swf when using cffile?
    By fivefiveSouth in forum Coldfusion Flash Integration
    Replies: 3
    Last Post: March 21st, 05:20 PM
  4. Incorrect mime type
    By davereif in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: March 11th, 03:26 AM
  5. MIME type Error
    By colesc8 in forum Coldfusion - Getting Started
    Replies: 1
    Last Post: March 8th, 02:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139