Professional Web Applications Themes

forum & binary cgi - Ruby

I too am new to Ruby, but i love it! Two questions though: 1. I read and printed a png image from disk and printed it to the browser but it doesnt't work: print "Content-type: image/png\n\n" file = File.new(imagePath, 'r') content = '' file.each_line {|line| content += line } file.close print content Could this have anything to do with binary mode? How could i get this to work? 2. What is the forum/community site where most Ruby experts hang out? Like Perl has perlmonks.org Thanks in advance, Teun van Eijsden The Netherlands...

  1. #1

    Default forum & binary cgi

    I too am new to Ruby, but i love it! Two questions though:

    1. I read and printed a png image from disk and printed it to the
    browser but it doesnt't work:

    print "Content-type: image/png\n\n"
    file = File.new(imagePath, 'r')
    content = ''
    file.each_line {|line| content += line }
    file.close
    print content

    Could this have anything to do with binary mode? How could i get this to
    work?

    2. What is the forum/community site where most Ruby experts hang out?
    Like Perl has perlmonks.org

    Thanks in advance,

    Teun van Eijsden
    The Netherlands

    Jaap Guest

  2. #2

    Default Re: forum & binary cgi

    On Sunday, December 28, 2003, 9:11:49 AM, Jaap wrote:
     
     
     
     

    Try this:

    print "Content-type: image/png\n\n"
    File.open(image_path, 'rb') do |file|
    content = file.read
    end # file is auto-closed here
    print content

    Explicitly closing a file is *so* last-century ;)

    You can use 'content = File.read(image_path)' but I'm not sure if
    that's read as text or binary.
     

    No real forum to speak of. That's what ruby-talk is for.

    Check out the Ruby Doentation Bundle (ruby-doc.org/downloads) for
    some meaty doentation and a newbie's guide to the Ruby community.
    Summary: ruby-talk, IRC, rubygarden.org, Wiki, RAA, RubyForge.

    Cheers,
    Gavin



    Gavin Guest

  3. #3

    Default Re: forum & binary cgi

    Gavin Sinclair wrote:
     

    Thank you very much. It works if i add STDOUT.binmode
    Now if i can only get those damn multipart file uploads working...

    Teun

    Jaap Guest

Similar Threads

  1. filestream binary
    By Shazbot in forum ASP.NET Web Services
    Replies: 4
    Last Post: February 2nd, 02:33 PM
  2. binary libphp4.so
    By Richard Jonker in forum PHP Development
    Replies: 0
    Last Post: January 11th, 09:46 AM
  3. CGI php Binary
    By Jan Fure in forum PHP Development
    Replies: 0
    Last Post: September 23rd, 06:13 PM
  4. Replies: 10
    Last Post: August 19th, 11:25 AM
  5. Replies: 5
    Last Post: June 26th, 12:31 AM

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