Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Automatic Uploader Script

by sadarax (Sexton)
on Dec 13, 2007 at 23:17 UTC ( [id://656940]=note: print w/replies, xml ) Need Help??


in reply to Re: Automatic Uploader Script
in thread Automatic Uploader Script

Wow Moklevat, that is a really cool. You definitely 'put up' the code.

I will certainly be using this, and working on getting that upload function working. If all goes well, I may try to spin this into a module like everyone suggested and throw it up on CPAN. That is of course, if you don't mind me using your code.

I'm still learning Modules, so it may take me a while though.

Replies are listed 'Best First'.
Re^3: Automatic Uploader Script
by moklevat (Priest) on Dec 14, 2007 at 01:05 UTC
    I, moklevat, release the code for use without restriction and without warranty of merchantability for any purpose (or whatever).
      I am sorry to have to come begging for more help, but I am thoroughly stuck on the upload code for this. I have tried a few variations, but nothing seems to work. I ended up using a form (as the API instructions specified), I don't know if my code will help at all.

      my $response_url = "www.divshare.com"; open my $FILE, "video.avi" or die "Cannot open file\n"; ## Attempt to upload a file my $upload = upload( $user_agent, $upload_ticket, $response_url, $FILE +, $folder_id, ); close $FILE; # Not yet Supported: Email, file_descript, and multiple files sub upload { my $post_url = 'http://upload.divshare.com/api/upload'; my ($user_agent, $upload_ticket, $response_url, $file1, $folder_id) += @_; my $html_form = '<form action="' . $post_url . '" method="post" enctype="multipart +/form-data"> <input type="hidden" name="upload_ticket" value="' . $upload_ticke +t . '" /> <input type="hidden" name="response_url" value="' . $response_url +. '" /> <input type="file" name="file1" /> <input type="text" name="file1_description" maxlength="255" /> <select name="folder_id"> <option value="' . $folder_id . '">[Folder Title 1]</option> </select> <input type="submit" value="Upload" /> </form>'; use HTML::Form; my $form = HTML::Form->parse($html_form, $post_url); # set form attributes $form->attr("upload_ticket", $upload_ticket); $form->attr("file1", $file1); $form->attr("file1_description", "$file1"); $form->attr("folder_id", $folder_id); push @{ $user_agent->requests_redirectable }, 'POST'; my $upload_response = $user_agent->request($form->click) or die "Use +r-Agent POST failed\n"; print $upload_response->base . "\n"; # Check the return object if( $upload_response->is_success ) { print "STATUS: " . $upload_response->status_line . "\n"; my $upload_xml = $upload_response -> content; if( defined $upload_xml && $upload_xml !~ "" ) { if( $upload_xml =~ "error" ) { print $upload_xml . "\n"; } } elsif( defined $upload_response ) { print "Returned no content\n Upload Response: $upload_response\n +"; } else { print "$upload_xml\n"; } return $upload_xml; } else { print STDERR $upload_response->status_line, "\n"; } }

      I typically get this print out when I run the script.

      http://www.divshare.com?error=true&description=Please+upload+a+file.
      STATUS: 200 OK
      Returned no content
      Upload Response: HTTP::Response=HASH(0x8a62e0c)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://656940]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-19 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found