I have an Android app that sends multipart data to a web server. The data consists of compressed binary data (which is actually a file but sent as data) and 2 text fields. Using CGI
$data = $q->param('param');
I can pick up the text data and filename easily enough but, whatever I do, I cannot get the binary data. The raw data coming into the server is
--mkGAOmWzlLaPNjkDQ57CNA9mUc6uoe1JMSRI Content-Disposition: form-data; name="mtdata"; filename="filename" Content-Type: application/octet-stream A whole lot of binary data --mkGAOmWzlLaPNjkDQ57CNA9mUc6uoe1JMSRI Content-Disposition: form-data; name="email" email address --mkGAOmWzlLaPNjkDQ57CNA9mUc6uoe1JMSRI Content-Disposition: form-data; name="mtfilename" file name --mkGAOmWzlLaPNjkDQ57CNA9mUc6uoe1JMSRI--
The CGI man page suggests
my $data = $query->param('POSTDATA');
If POSTed data is not of type application/x-www-form-urlencoded or multipart/form-data but that doesn't work. I've also tried:-
$lightweight_fh = $q->upload('field_name'); # undef may be returned if it's not a valid file handle if (defined $lightweight_fh) { # Upgrade the handle to one compatible with IO::Handle: my $io_handle = $lightweight_fh->handle; open (OUTFILE,'>>','/usr/local/web/users/feedback'); while ($bytesread = $io_handle->read($buffer,1024)) { print OUTFILE $buffer; } }
but that's not working either. I cannot (at the moment) change the content type of the uploaded data - can anyone see what I'm doing wrong?

In reply to Problem uploading file data using CGI by dougconran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.