Note that there are some explanatory texts on larger screens.

plurals
  1. POSave chart image with open flash chart2
    text
    copied!<p>I am using <a href="http://teethgrinder.co.uk/open-flash-chart-2" rel="nofollow noreferrer">Open Flash Chart 2</a> to create some graphs. I want to be able to save an image of the graph, which OFC2 supplies some methods to accomplish this. I used the example on the OFC2 site to directly display the raw image data on the page, but that does not work in IE6, which most of our users are using (I know, I know).</p> <p>I switched to using the OFC2 method, <code>post_image</code> to post the raw image data to the server. I use a Perl script to receive the image data, save it to a file, and I can view the image. The unfortunate part about using the <code>post_image</code> method is that ActionScript throws an error when saving the image: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.</p> <p>Which apparently is a bug in Adobe - see <a href="http://www.actionscript.org/forums/showthread.php3?t=196454" rel="nofollow noreferrer">this page</a>. Because of this error, the <code>post_image</code> method does not complete successfully, so the javascript callback won't ever fire - I basically don't have a way to tell if the image was saved successfully.</p> <p>So, I thought I would use the <code>get_img_binary</code> method of OFC2 to get the binary data of the image, and use jQuery to post the binary data to my Perl script.</p> <p>I cannot figure out how to send the binary data correctly, or how to let my Perl script receive the binary data correctly, or both.</p> <p>Here is my jQuery function:</p> <pre><code> var chartObj = $("#chart_object").get(0); $.ajax({ type: "POST", url: 'download_image.pl', //contentType: 'application/octet-stream', contentType: 'image/png', //processData: false, //data: { imgData: chartObj.get_img_binary() }, data: chartObj.get_img_binary(), dataType: "text", success: function(data) { console.log( data ); } }); </code></pre> <p>You can see from some of my commented out lines that I have tried various contentTypes and other settings of the Ajax call.</p> <p>The Ajax call is sending some data, but it doesn't appear to be binary. I think it is a base64 representation of the binary data.</p> <p>Does anyone have any ideas on how to send binary data from javascript to the server?</p> <p>The Perl script I have works fine for the <code>post_image</code> method, so I don't think the problem is there?</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload