Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transfer image with LWP::Request and check size

Status
Not open for further replies.

webscripter

Programmer
Jul 29, 2002
266
US
I'm trying to transfer an image and want to use LWP::Request so I can check the filesize and content-type.

The code compiles, but doesn't transfer the content.
I put alot of traces in and would rather not use mirror, or LWP::Simple. I need the files to transfer everytime and make sure the size and content-type are correct before writing the image.


Code:
	my$i = 0;
	foreach(@images){
		if(/\w/){
			# rename the images so they are harder to open
			my$filename = $_;
			#$filename =~ s/\./_/;
			print STDERR "\n filename = $filename";
			/(.*)\.(.*)\./;
			my$field = $_;	my$suffix = $_;
			$field =~ s/\.(.*)//g;	$suffix =~ s/(.*)\.//g;
			print STDERR "\n field = $field";
			print STDERR "\n suffix = $suffix";
			my$path = "$domain/$catg/$sesn/$dir$filename";
		
			my$url = "[URL unfurl="true"]http://$domain2$html/${demo}images/layout/$sesn/$dir$_";[/URL]
			my$req = HTTP::Request->new(POST => $url);
			my$response = $ua->request($req);
			if($response->is_success){
			print STDERR "\n content_type ".$response->content_type;
				unless($response->content_type eq "image/$suffix"){
					print STDERR "\n content-type is wrong ".$response->content_type;
					next;
				}
				if($i == 0){
					$i=1;
					print STDERR "\n\n******************************\n".$response->content."\n******************************\n\n";}
				if(open(IMAGE, ">./unchecked/$path")){
				#	binmode(*IMAGE);
					lockit(*IMAGE,2);
					print IMAGE $response->content;
					unlockit(*IMAGE);
					close(IMAGE);
					print STDERR "\n Wrote ./unchecked/$path";
				}else{
					$done = 0;
					print STDERR "\n**IMAGE** Couldn't write ./unchecked/$path";
					print "\n <BR>**IMAGE** Couldn't write ./unchecked/$path";
				}
				my$content = $response->content;
				$content =~ s@'@\'@g;
				my$stmt = "INSERT INTO STYLE_PICTURES_${domain}_${catg}_$sesn WHERE $field='$response->content');";
				#print STDERR "\n$stmt";
				eval{
					$pkg::dbh->do($stmt);
				};
				mysql_errors($stmt);
			}else{
				$done = 0;
				print STDERR "Couldn't transfer $url".$response->status_line;
				push(@pkg::messages, "Couldn't transfer $url  ".$response->status_line);
			}
		}
	}

Thankyou for your help.

Thanks
Pat
ideas@microwebber.com
 
I solved the problem by using LWP::Simple along side of LWP::Request.
If someone has better code please post it for me.
Thanks

Thanks
Pat
ideas@microwebber.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top