View unanswered posts | View active topics It is currently Thu Jul 31, 2014 2:29 pm



Reply to topic  [ 2 posts ] 
FTP upload images rather than zips (solved) 
Author Message

Joined: Thu Oct 11, 2007 6:10 am
Posts: 186
Post FTP upload images rather than zips (solved)
So I never really saw the point in uploading zips of events. Zip doesn't further compress JPGs by default, so all you get is a single file that has to be downloaded and uncompressed rather than being viewed in a browser. I want offsite backups that are quick and easy to scan, and by the above they take up no more room than the zips did anyway. So I modified "sub uploadArchFile" in zmfilter.pl a little bit to:

1. Create a directory called <monitor name>-<event Id>

2. Upload the *capture.jpg files into that directory

3. Create a temporary "event.html" file that shows 160x120 thumbnails of all the uploaded jpgs on one page and allows clicking on them to enlarge to the full image, uploads the event.html file into the directory in #1 above, and then erases the event.html file from ZM_UPLOAD_FTP_LOC_DIR.

Then you can have your email alert do something like:

http://www.MYDOMAIN.com/MY_FTP_UPLOAD_FOLDER/%MN%-%EI%/event.html

where MY_FTP_UPLOAD_FOLDER requires http basic authentication (at least). Then when you click on the link in the email, you authenticate and go straight to the offsite-backup location and view the group of thumbnails that make up the event.

4. Oh, and I just commented out the code that actually creates the archive (after applying some edits that fixed the "blank zip upload" issue on ubuntu 7.10).

My theory behind this is that for events I generally want to quickly scan what happened, and maybe download a few frames here and there after looking at the equivalent of an online contact sheet, rather than download zips, unpack them, view each image, and save the ones I want.

Here are the changed bits from zmfilter.pl:

Code:
sub uploadArchFile
{
    my $filter = shift;
    my $event = shift;

    my $ftp_create_dir = $event->{MonitorName} . '-' . $event->{Id};
    my $ftp_html_file = ZM_UPLOAD_FTP_LOC_DIR . '/' . "event.html";
    my $arch_file = ZM_UPLOAD_FTP_LOC_DIR.'/'.$event->{MonitorName}.'-'.$event->{Id};
    my $arch_image_path = getEventPath( $event ) . "/";
    #my $arch_image_path = getEventPath( $event )."/".((ZM_UPLOAD_ARCH_ANALYSE)?'{*analyse,*capture}':'*capture').".jpg";
    my $arch_error;

 
    if ( ZM_UPLOAD_ARCH_FORMAT eq "zip" )
    {
#        $arch_file .= '.zip';
#        my $zip = Archive::Zip->new();
#        Info( "Creating upload file '$arch_file'\n" );
#        Info( "Arch_image_path is '<$arch_image_path>'\n" );

        my $status = &AZ_OK;
#       foreach my $image_file ( <$arch_image_path/*capture.jpg> )
#      {
#            Info( "Adding $image_file\n" );
#            my $member = $zip->addFile( $image_file );
#            last unless ( $member );
#            $member->desiredCompressionMethod( (ZM_UPLOAD_ARCH_COMPRESS)?&COMPRESSION_DEFLATED:&COMPRESSION_STORED );
#        }
#        $status = $zip->writeToFileNamed( $arch_file );

#        if ( $arch_error = ($status != &AZ_OK) )
#        {
#            Error( "Zip error: $status\n " );
#        }
    }
    elsif ( ZM_UPLOAD_ARCH_FORMAT eq "tar" )
    {
        if ( ZM_UPLOAD_ARCH_COMPRESS )
        {
            $arch_file .= '.tar.gz';
        }
        else
        {
            $arch_file .= '.tar';
        }
        Info( "Creating upload file '$arch_file'\n" );

        if ( $arch_error = !Archive::Tar->create_archive( $arch_file, ZM_UPLOAD_ARCH_COMPRESS, <*$arch_image_path> ) )
        {
            Error( "Tar error: ".Archive::Tar->error()."\n " );
        }
    }

    if ( $arch_error )
    {
        return( 0 );
    }
    else
    {
        Info( "Uploading to ".ZM_UPLOAD_FTP_HOST."\n" );
        my $ftp = Net::FTP->new( ZM_UPLOAD_FTP_HOST, Timeout=>ZM_UPLOAD_FTP_TIMEOUT, Passive=>ZM_UPLOAD_FTP_PASSIVE, Debug=>ZM_UPLOAD_FTP_DEBUG );
        if ( !$ftp )
        {
            warn( "Can't create ftp connection: $@" );
            return( 0 );
        }

        $ftp->login( ZM_UPLOAD_FTP_USER, ZM_UPLOAD_FTP_PASS ) or warn( "FTP - Can't login" );
        $ftp->binary() or warn( "FTP - Can't go binary" );
        $ftp->cwd( ZM_UPLOAD_FTP_REM_DIR ) or warn( "FTP - Can't cwd" );
   $ftp->mkdir($ftp_create_dir) or warn( "Cannot create directory $ftp_create_dir");
   $ftp->cwd($ftp_create_dir) or warn( "FTP - can't cwd to $ftp_create_dir");
   my $event_html_text = '';
        foreach my $image_file ( <$arch_image_path/*capture.jpg> ) {
           $ftp->put( $image_file ) or warn( "FTP - Can't upload '$image_file'" );
      (my $short_image_file = $image_file) =~ s/.*\///;
      $event_html_text = $event_html_text . "<a href=\"$short_image_file\"><img src=\"$short_image_file\" width=160 height=120 border=0></a>";
        }
   open MYHTML, ">> $ftp_html_file" or warn ("Can't create or open HTML file");
   print MYHTML "$event_html_text" or die ("Can't print to $ftp_html_file");
   close MYHTML;
   $ftp->ascii();
   $ftp->put( $ftp_html_file );
   unlink( $ftp_html_file);
        #$ftp->put( $arch_file ) or warn( "FTP - Can't upload '$arch_file'" );
        $ftp->quit() or warn( "FTP - Can't quit" );
        unlink( $arch_file );
        my $sql = "update Events set Uploaded = 1 where Id = ?";
        my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
        my $res = $sth->execute( $event->{Id} ) or Fatal( "Can't execute '$sql': ".$sth->errstr() );
    }
    return( 1 );
}


Obviously this is a total hack job, but maybe it'll provide some ideas to someone down the road. You can do a *lot* with event.html. The clever could create a little slideshow javascript, or something with next/prev buttons...possibilities are wonderful here.


Mon Jun 02, 2008 8:13 pm
Profile

Joined: Fri May 29, 2009 10:56 pm
Posts: 15
Post 
Hey Haus, I see this is a very old post, but interestingly enough, this issue is still not fixed in the actual released versions! I backed up my zmfilter.pl and added your modifications to mine, and it works great!

One question: Would it be possible to make the event.html a little more rich, with just maybe a couple options:

1. When you go to event.html initially, if it would do a streaming .jpg like the way ZM does in the regular monitoring view, rather than just the thumbnails. and if so, also just a "thumbs" link on the event.html which would take you to the full page of thumbs, as the event.html currently displays. What do you think?

Second question for you: Is there a way to have it convert to .mpg video when a filter is triggered, upload that video, then notify by email of the event, with a link to the video? I'm probably asking way too much, but hopefully not!


Thu Feb 11, 2010 12:56 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group