Manual:Pywikibot/upload.py

upload.py is a Pywikibot script used to upload images to a wiki.

Arguments
If any other arguments are given, the first is the URL or filename to upload, and the rest is a proposed description to go with the upload. If none of these are given, the user is asked for the file or URL to upload. The bot will then upload the image to the wiki.

The script will ask for the location of an image, if not given as a parameter, and for a description.

If the -filename argument is given, then it is used as the name of the image on the wiki; otherwise it is based on the filename or url of the input file.

If -keep is not specified, then the target filename undergoes some further checking, and the user is asked for confirmation. The / character is forbidden, and the filename extension (after the dot) must be one of these: gif, jpg, jpeg, mid, midi, ogg, png, svg, xcf, djvu, pdf. If the check is failed, then the user is prompted for a new filename.

If an image with the target filename already exists, the description will not be overwritten with the supplied description text. Instead, the description text will be added as a comment.

Spaces in the filename will automatically be converted to underscores, since mediawiki doesn't allow spaces. The encoding of the filename will also be converted to the encoding used on the target site (typically unicode). The script also attempts to convert the description to the wiki's target encoding, or, as a last resort, will convert characters to html entities.

Error detection is based on both the http status and the contents of the response, which is assumed to be in English; error detection may fail if the bot's account has been set not to show an English interface.

Note: Very large files that are uploaded to Wikimedia Commons: are best uploaded with the chunked parameter. — billinghurst  sDrewth  13:19, 22 January 2020 (UTC)

Output example
Example of output if no file name is given:

Examples
Where des/0 is the path of a file indicating the description of the file.

Note that the first parameter after 'upload' is the local image directory (spaces in the name must be escaped with a backslash(\) ); the second parameter is the upload description surrounded by double quotes; the three parameters after that are needed for batch uploads.