I'm trying to display a generated .png plot via send_data(), but it
results in a server error "invalid byte sequence in US-ASCII" error.
I'm pretty sure this means that I need to specify the encoding
somewhere, but I haven't been able to figure out where or how to do so.
I'm running gnuplot through a pipe to generate a plot in .png format.
(I've tested the code by writing its output to a file and displaying it
-- it works.) My Report model receives the .png image as a string:
class Report << ActiveRecord::Base
image = GnuPlot(@gnuplot_commands)
My Controller uses send_data() to serve up a page:
class ReportsController < ApplicationController
report = Report.find(params[:id])
send_data(report.imagedata, :type => 'image/gif')
[FWIW, without really understanding it, I also tried added an :encoding
=> 'utf8' to the send_data call -- no change.] Finally, my View presents
<img src="<%= url_for(:controller => 'reports', :action => 'plot')
However, the send_data() call results in a server error:
ArgumentError (invalid byte sequence in US-ASCII):
So the question: Where do I specify the encoding? And what encoding is
appropriate for a .png binary?
"rails --version" => Rails 2.3.5
"ruby --version" => ruby 1.9.1p376
"mysqul --vesion" => Ver 14.14 Distrib 5.1.36
OS = Mac OS X 10.5.8