jQuery-File-Upload-Imager

 view release on metacpan or  search on metacpan

lib/jQuery/File/Upload/Imager.pm  view on Meta::CPAN

	my $self = shift;

	for(@{$self->scp}) {
		die "Must provide a host to scp" if $_->{host} eq '';

		$_->{thumbnail_upload_dir} = $_->{upload_dir} if $_->{thumbnail_upload_dir} eq '';

		my $path = $_->{upload_dir} . '/' . $self->filename;
		my $thumb_path = $_->{thumbnail_upload_dir} . '/' . $self->thumbnail_filename;

		if(($_->{user} ne '' and $_->{public_key} ne '' and $_->{private_key} ne '') or ($_->{user} ne '' and $_->{password} ne '')) {
			my $ssh2 = $self->_auth_user($_);

			#if it is an image, scp both file and thumbnail
			if($self->is_image) {
				$ssh2->scp_put($self->{tmp_file_path}, $path);
				$ssh2->scp_put($self->{tmp_thumb_path}, $thumb_path);
			}
			else {
				$ssh2->scp_put($self->{tmp_filename}, $path);
			}

lib/jQuery/File/Upload/Imager.pm  view on Meta::CPAN


sub _auth_user {
	my $self = shift;
	my ($auth) = @_;

	my $ssh2 = Net::SSH2->new;

	$ssh2->connect($auth->{host}) or die $!;

	#authenticate
	if($auth->{user} ne '' and $auth->{public_key} ne '' and $auth->{private_key} ne '') {
		$ssh2->auth_publickey($auth->{user},$auth->{public_key},$auth->{private_key});
	}
	else {
		$ssh2->auth_password($auth->{user},$auth->{password});
	}

	unless($ssh2->auth_ok) {
		die "error authenticating with remote server";
	}

	die "upload directory must be provided with scp hash" if $auth->{upload_dir} eq '';

lib/jQuery/File/Upload/Imager.pm  view on Meta::CPAN

=back

=head2 A more complicated example

  use jQuery::File::Upload::Imager;

  my $j_fu = jQuery::File::Upload::Imager->new(
		scp => [{
			user => 'user', #remote user
			public_key => '/home/user/.ssh/id_rsa.pub',	#also possible to use password instead of keys
			private_key => '/home/user/.ssh/id_rsa',
			host => 'mydomain.com',
			upload_dir => '/var/www/html/files', #directory that files will be uploaded to
		}],

		#user validation specifications
		max_file_size => 5242880, #max file size is 5mb
		min_file_size => 1,
		accept_file_types => ['image/jpeg','image/png','image/gif','text/html'], #uploads restricted to these filetypes
		max_width => 40000, #max width for images
		max_height => 50000, #max height for images

lib/jQuery/File/Upload/Imager.pm  view on Meta::CPAN

remove it with your own clean up script later. The benefit to this could be that
if you are SCPing the files to a remote server, perhaps issuing the remote commands
to delete these files is something that seems to costly to you.

=head3 scp

  $j_fu->scp([{
			host => 'media.mydomain.com',
			user => 'user',
		  	public_key => '/home/user/.ssh/id_rsa.pub',
		  	private_key => '/home/user/.ssh/id_rsa',
			password => 'pass', #if keys are present, you do not need password
			upload_dir => '/my/remote/dir',
		}]);

This method takes in an arrayref of hashrefs, where each hashref is a remote host you would like to SCP the files to.
SCPing the uploaded files to remote hosts could be useful if say you hosted your images on a different server
than the one doing the uploading.

=head4 SCP OPTIONS

lib/jQuery/File/Upload/Imager.pm  view on Meta::CPAN

=item

host (REQUIRED) - the remote host you want to scp the files to, i.e. 127.0.0.1 or media.mydomain.com

=item

user (REQUIRED) - used to identify the user to remote server

=item

public_key & private_key - used to make secure connection. Not needed if password is given.

=item

password - used along with user to authenticate with remote server. Not needed if keys are supplied.

=item

upload_dir (REQUIRED) - the directory you want to scp to on the remote server. Should not end with a slash

=item



( run in 0.499 second using v1.01-cache-2.11-cpan-a5abf4f5562 )