Note that there are some explanatory texts on larger screens.

plurals
  1. PORails POST Content-type = image/jpeg
    primarykey
    data
    text
    <p>I have an axis camera which POSTS data to an address I give it. I would like it to post data to a rails application, but I haven't found any examples of how to do that. The only information I have to work with is the header for the post request. I pulled a few things out, but here's what I got:</p> <pre><code>REQUEST_METHOD = POST QUERY_STRING = CONTENT_TYPE = image/jpeg DOCUMENT_ROOT = /var/www/staging/public REQUEST_URI = /camera/1/images? SCRIPT_NAME = PATH_INFO = /camera/1/images HTTP_CONTENT_DISPOSITION = attachment; filename="image09-12-16_21-16-28-90.jpg" _ = _ </code></pre> <p>As far as I can tell, The request itself contains the JPEG Image.</p> <p>Axis publishes the following as a CGI script to save the images. It works, but I want it to be a part of my Rails app:</p> <pre><code>#!/usr/bin/perl -w my $upload_dir = "/var/www/cgi-bin/upload/"; print "Content-Type: text/plain\r\n\r\n"; print "Upload OK\r\n"; my $file_name = $ENV{'HTTP_CONTENT_DISPOSITION'}; $file_name =~ s/^attachment; filename=\"(.*)\"$/$1/; open (IMG_FILE, "&gt; $upload_dir$file_name") or die "can't open &gt;$upload_dir$file_name"; binmode(IMG_FILE); while (&lt;STDIN&gt;) { print IMG_FILE $_; } chmod 0666, "$upload_dir$file_name"; exit 0; </code></pre> <p>So the filename is in ENV{'HTTP_CONTENT_DISPOSITION'}, which is clear in both the headers and the sample code. It seems, from the perl script, that the image data is all contained in STDIN. I have tried the following in rails:</p> <pre><code>imagefile = File.new("test_file.jpg","w+") imagefile &lt;&lt; STDIN.read imagefile.close </code></pre> <p>but it did not work. The file test_file.jpg was empty.</p> <p>Is there anything I am mission? Does anyone know how to save the request data as a file?</p> <p>Does anyone know of any good libraries that allow http upload from Axis webcams?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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