Hello. I have a perl cgi script that I use to process a zip file, and the create a new zip output for download. I want to do this without writing the output zip file to the disk The zip output is actually raw binary data, not a file.

When I print the binary zip data with application/zip content headers, it works fine, the zip downloads, no problem. However, I'd like to refresh the current page and then output the zip data. In order to do this, I pass the binary data as params and call on the script again to output the data. When I do this, the zip file gets corrupted, I think because the parameters are getting read as text instead of binary data.

My question is, is there a way to pass raw binary data as form parameters and have a script read them as raw binary data?

In case you're wondering, Yes, I could save it to the disk and solve my problems, but I want to avoid that. if possible,

below is the form that I use to pass the seperate headers and the binary data.

print $cgi->start_multipart_form(-action=>'site.cgi', -method=>"POST", + -id=>"hiddenform"); print $cgi->hidden('theoutput',"$_[0]"); //the binary data print $cgi->hidden('theheader',"$_[1]"); //the header data print $cgi->end_multipart_form;

as a test, I can write the $_[0] to a file and it works fine:

open FILE, ">", "uploaded/anything.zip" or die $!; print FILE $_[0]; close FILE

and anyting.zip is a working zipfile.

but, when I obtain the parameters and try the same thing, the zipfile gets corrupted.

my $content = $cgi->param('theoutput'); open FILE, ">", "uploaded/anything.zip" or die $!; print FILE $content; close FILE

EDIT:::: Perhaps I should clarify what I actually want to do and maybe there's a better solution out there

I have a script that allows a user to upload a zip file through a web form. (we'll call it the Upload Page). It then processes that zip file using an external java program which outputs either raw html or raw binary data. While the java program processes the upload, I have a div overlayed on the Upload Page that becomes visibile to show that the request is being processed.

once the java process is done, the script prints the output as a new page. With the html output, this works great, it will print as a new page which replaces the old UploadPage. The problem is with the zip file, the original Upload page is still visible, and the "loading" div is still visible.

What I'd like to do in the case of the zip output is make the original UploadPage visible as it was before

so far, these are the options I've tried

1. Removing the "loading" div once the java process completes. This doesn't work because I believe once the form is submitted, I no longe rhave access to the elements of the original page.

2. Outputting the html of the original upload page as a new page, and then outputting the zipbinary data. This doesn't work because it will just show raw binary data printed at the bottom of the page

3. outputting th ehtml of the original upload page as a new page, and then putting the zip binary data as the source of a hidden iframe. this doesn't work because I couldn't figure out how to have the iframe source be non-html, binary zip data

4. outputting the original upload page as a new page, and then reloading the page using the binary zip data passed parameters to print as the page reload (That was the topic of the original post, which isn't working as I've described already)

5. I thought maybe CGI::Ajax might be the way to go, but I've looked into it and not sure how I can utilize it to my advantage

The other option I thought of is some way of calling some sort of -onsubmitcomplete=> option for my form, meaning once the script is done processing, the upload form submission, I take down the div, or reload the page, or whatever. But I don't think that exists.

I really have no idea what else to try. I really thought I had it with the passing of the binary data as a parameter,


In reply to Cgi params as binary data by atey1

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.