Reputation: 24580
I'm trying to save an image from a Flash AS3 to my server as a jpg file. I found some PHP code to do this, but I want to do this in Ruby. I'm not quite sure how to convert the following code to Ruby. It's mainly the $GLOBALS["HTTP_RAW_POST_DATA"]
part I don't know how to convert.
<?php
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
// get bytearray $im = $GLOBALS["HTTP_RAW_POST_DATA"];
// save image $f = fopen($_GET['name'], 'wb'); fwrite($f, $jpg); fclose($f);
} else echo 'An error occured.';
?>
source:
http://designreviver.com/tutorials/actionscript-3-jpeg-encoder-revealed-saving-images-from-flash/
I tried to do the following, but the resulted image file dose not open
temp_file = Tempfile.new(['temp', '.jpg'], :encoding => 'ascii-8bit')
temp_file.write(request.raw_post)
temp_file.close
EDIT
The image data is in request.raw_post
EDIT2
As for the image being sent, here is how the header is created in AS3
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var saveJPG:URLRequest = new URLRequest("http://127.0.0.1:3000/save_image.xml");
saveJPG.requestHeaders.push(header);
saveJPG.method = URLRequestMethod.POST;
Upvotes: 2
Views: 519
Reputation: 14943
$GLOBALS["HTTP_RAW_POST_DATA"]
can be grabbed from
request.env["HTTP_RAW_POST_DATA"]
and save it like https://stackoverflow.com/a/2571575/643500
Edit:
Isn't the image data in request.body
?
I need to see how the image is being sent. Do you have a header with the Content-Type
?
Upvotes: 1