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?