Commons talk:File upload service/Script

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

I've found that a sleep(15) at the end of the while loop makes it have a lot fewer timeouts which result in files not being uploaded. I'm guessing it's best for the servers anyway. Dori | Talk 21:50, 24 Apr 2005 (UTC)

use strict; and use warnings;[edit]

Hi,

Shouldn't you have:

  • use strict;
  • use warnings;

GavinHenry 14:29, 16 May 2005 (UTC)[reply]

False positive notification[edit]

Files must be at least 3 chars long. It's a rule set by the wiki software probably to have enough characters to hash into the images directory.
script will report successful upload but files wont be in the wiki — Jctong 04:47, 22 November 2005 (UTC)[reply]

Annoyingly, the script also reports successful upload if you don't have the right to overwrite files (new user), but try to do so using the script. Anyway, a big Thank you! to Eloquence -Pumbaa 17:58, 30 March 2006 (UTC)[reply]

Existing Files[edit]

I've just started using this on my own Wiki and have found that if a file already exists, then it is simply replaced, it would be better if it wasn't.

I also added the following at line 97 to remove "\r" which seemed to be upsetting the script. (My files.txt file was created under Windows and I'm running the Perl scrip on Linux).

$line=~s|\r||gi;

Otherwise and excellent script, thanks.

I think automatic file replacement can simply be disabled by removing the line wpIgnoreWarning=>"1" (l.181) or by replacing it with wpIgnoreWarning=>"0" -Pumbaa 17:51, 30 March 2006 (UTC)[reply]

Script doesn't work with MW<1.5[edit]

The Script won't run on Wikis using MediaWiki below Version 1.5. --Rhododendronbusch 12:49, 8 February 2006 (UTC)[reply]

To get it work, change the lines 176 to 182 to the following:
@ns_headers,Content_Type=>'form-data',Content=>
[
    wpUploadFile=>["$dir/$eckey"],
    wpDestFile=>$key,
    wpUploadDescription=>encode("iso-8859-1",$file{$key}),
    wpUpload=>"Dateien hochladen"
]);
Line 181 must be adapted to the localization. --Rhododendronbusch 13:12, 8 February 2006 (UTC)[reply]
Oh, and don't forget to adapt the encoding to your wiki ;) --Rhododendronbusch 13:12, 8 February 2006 (UTC)[reply]

script can't find any files to upload[edit]

I shouldn't be posting this support question here, but Eloquence has stopped accepting email. :-(

When I run this script on Linux with perl 5.8.8, the following is the output.

$ perl upload.pl commons-photos
. Uploading no files.s-photos/AYE Teban flyover.JPG

And the files are not uploaded.

Any one has an idea what is the problem? Kimchi.sg | Talk 16:34, 31 March 2006 (UTC)[reply]

Looks like the output results from
Could not find commons-photos/AYE Teban flyover.JPG[Carriage return]. Uploading no files.
It seems your files.txt contains contains incorrect line end characters. Try saving it with a different editor. --Pumbaa 13:27, 1 April 2006 (UTC)[reply]

Bot Necessary?[edit]

Is it necessary to create a "bot account" if I'm only using this to upload images that I've taken? I've been out taking a lot of pictures that I'd like to upload and include in a variety of articles, so I do want to use a scripted upload, but I'm not planning on uploading others' work. --Ron Johnson 05:03, 11 April 2006 (UTC)[reply]

Not really. If you plan on uploading hundreds or thousands of files though, probably. See Commons:Bots. Especially note that if your bot doesn't perform categorisation, you should manually, and you should be prepared to correct any mistakes your bot makes. pfctdayelise (translate?) 11:47, 11 April 2006 (UTC)[reply]

Thank you[edit]

Thank you very much for this bot, I used your source to upload images to my own wiki[1].

It worked right away, no fiddling, I just had to change the urls to my wiki's. Keep up the good work. HighInBC 02:23, 17 May 2006 (UTC)[reply]

The input field Destination file would be great[edit]

Most digital images have names like IMG_XXXX.JPG odr DSCXXXX.JPG, it would be great if there would be an additional line in files.txt for the destination name ibn wikipedia.

So, adding a line with a special character, e.g. § in the files.txt and then in the real upload one more field like:

wpDestFile=>encode('utf8',$file{$destname});

MatthiasKabel 13:19, 2 July 2006 (UTC)[reply]

Give the file a meaningful name for Commons in your hard drive before you do the upload. – Tintazul talk 05:28, 2 August 2006 (UTC)[reply]

Errors with encode utf8[edit]

I have had problems with script when trying to upload images and descriptions with spanish characters (accents and eñes), these not appear correctly. I use everything with utf8 and when script use filename and descriptions reencode this to utf8, appeared the characters with strange symbols. If I change "$eckey=encode('utf8',$key);" by "$eckey=$key;" and "wpUploadDescription=>encode('utf8',$file{$key})," by "wpUploadDescription=>$file{$key}," everything works ok. It would be commented in script. Thank's, the script is great. --Bigsus 08:23, 18 July 2006 (UTC)[reply]

error message[edit]

When only one file is in files.txt, i get an error like this: Can't open file pegasus.jpg: No such file or directory at /Library/Perl/5.8.6/LWP/UserAgent.pm line 427

When multiple files are in files.txt, I get a 403 Forbidden response from the server (I am using this on my own wiki)

Could someone help please?

Thanks

Fixing timeouts[edit]

Instead of adding a sleep statement, I added this:

$browser->timeout(600);

after the line that says $browser->cookie_jar( {} );. It stopped my 500 internal error timeout messages.

Does anyone know how to modify this so that images are automatically added to your watchlist? It is annoying that they are not... --pfctdayelise (说什么?) 00:26, 18 January 2007 (UTC)[reply]