Creating a Zip file from HTTP data stream

Discussion in 'Perl Misc' started by Yasir Zaheer, Jul 8, 2009.

  1. Yasir Zaheer

    Yasir Zaheer Guest

    Hi all,

    I am facing some problems in creating a zip file coming as HTTP data
    stream in perl running over Linux RedHat 4. The actual scenario is
    that I am recieving a data stream send by a .Net application running
    on windows XP that sends the stream by just reading and sending all
    the bytes from a zip file. My logs displays all the data recieved in
    the varialbe $$params{LOG} on console but i am unable to create a zip
    file out of that. Any help in this regards will be appreciated.


    use core qw ( CGI_USER ) ;
    use utils::MailMime;
    $core::dbh->ensureWebAlive();
    my $osysconfig = sysconfig->new({MINIMAL => '1'});
    use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

    my $params = CGI::Vars();
    use Archive::Zip qw( :ERROR_CODES );
    #print "Content-type:text/html\n\n";
    print header;

    my $MAILTO = '';


    my $MAILFROM = '';

    my $smtp = $osysconfig->GetSMTPServer();
    my $port = $osysconfig->GetSMTPServerPort();
    my $host = hostname();
    my $omailer = MailMime->new( { SMTPSERVER=> $smtp, SMTPSERVERPORT =>
    $port } );

    # $$params{LOG} ---- this is the binary zipped file which i have to
    attached with email.
    if (($$params{LOG}) and (not $$params{REMOTEFILE}))
    {
    $file = '/tmp/tmp.zip' ;
    #use Archive::Zip;

    #my $zip = new Archive::Zip;

    #my $data = "$$params{LOG}";

    #$zip->addString($data,"LOG");
    #$zip->writeToFileNamed($$params{LOG});
    #print FILE $$params{LOG};
    #close FILE;

    #give read write permission to all
    #`chmod 666 $file`;
    my $fh;
    #open ( $fh , '>', $file ) or $core::logger->Die( 'Error opening
    file', $@);

    #print $fh "$$params{LOG}";
    #if (defined $$params{LOG});
    #print $fh $$params{SCREENSHOT}
    #if (defined $$params{SCREENSHOT});
    close $fh;

    }

    my $text = "Application logs are attached\n\nDetails of the sender:\n
    \nLogin:$$params{LOGIN} \nServer Address: $host";
    $text .= "\n\n$$params{USERTEXT}" if ( $$params{USERTEXT} );
    my %Ret;

    if (($$params{LOG}) and (not $$params{REMOTEFILE}))
    {
    eval
    {
    %Ret = $omailer->SendFile({

    From => $MAILFROM,
    To => $MAILTO,
    Subject => "Application Report from $$params{LOGIN} on $host",
    Text => $text ,
    Path => $file,
    Type => 'binary'
    }) or die "Could not send mail [$!]";
    };
    }
    if ( $@ )
    {
    print "$@\n";
    }
    else
    {
    print "1";
    }






    regards,
    Yasir.
     
    Yasir Zaheer, Jul 8, 2009
    #1
    1. Advertising

  2. Yasir Zaheer wrote:
    > Hi all,
    >
    > I am facing some problems in creating a zip file coming as HTTP data
    > stream in perl running over Linux RedHat 4. The actual scenario is
    > that I am recieving a data stream send by a .Net application running
    > on windows XP that sends the stream by just reading and sending all
    > the bytes from a zip file. My logs displays all the data recieved in
    > the varialbe $$params{LOG} on console but i am unable to create a zip
    > file out of that. Any help in this regards will be appreciated.
    >
    >

    ....
    > use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

    ....
    > use Archive::Zip qw( :ERROR_CODES );

    ....

    Is that real code?

    If you have the all the bytes of a zip file in $$params{LOG}, can't you
    simply 'print' that variable to a binary file without using Archive::Zip?

    By the way, wouldn't that be better written as $params->{'LOG'}?
    Are you using the 'strict' and 'warnings' pragmas?

    --
    RGB
     
    RedGrittyBrick, Jul 8, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,731
  2. abcd
    Replies:
    7
    Views:
    513
    Edward Elliott
    May 1, 2006
  3. majj81
    Replies:
    0
    Views:
    336
    majj81
    May 31, 2006
  4. Chris Lambacher

    Re: Add file to zip, or replace file in zip

    Chris Lambacher, Jun 1, 2006, in forum: Python
    Replies:
    0
    Views:
    608
    Chris Lambacher
    Jun 1, 2006
  5. m.niinimaki
    Replies:
    9
    Views:
    1,079
    steph
    Aug 29, 2010
Loading...

Share This Page