API:Upload/fr

Requête POST pour téléverser un fichier.

Il existe trois méthodes pour téléverser des fichiers via l'API :


 * 1) Téléverser un fichier local directement
 * 2) Téléverser une copie d'un fichier à partir d'une URL
 * 3) Téléverser un fichier local par parties

Toutes ces méthodes imposent que le compte a les droits.

Upload warnings
Note that an upload may fail due to a number of warning conditions. This can be overridden by setting. Some notable warnings include:


 * exists: A file with the given name already exists. If this warning is ignored, the uploaded file will replace the existing file.
 * no-change: A file with the given name already exists and is exactly the same as the uploaded file.
 * duplicate-version: A file with the given name already exists and and old version of that file is exactly the same as the uploaded file.
 * was-deleted: a file with the given name used to exist but has been deleted.
 * duplicate: The uploaded file exists under a different (or the same) name. Uploading a duplicate may be undesirable.
 * duplicate-archive: The uploaded used to exist under a different (or the same) name but has been deleted. This may indicate that the file is inappropriate and should not be uploaded.

Exemple
Faire une requête POST donnée est un processus en plusieurs étapes :

 Log in, via one of the methods described in . GET a :

 Send a POST request, with the CSRF token to upload a file. 

Exemple n°1 : téléverser directement un fichier local
When uploading files directly, the request must use  as Content-Type or enctype,   will not work.

Exemple n°2 : téléverser un fichier depuis une URL
This requires  in the wiki's local settings and an account with the   user right.

Exemple n°3 : téléverser un fichier par parties
Since uploading a huge file in a single HTTP POST can be unreliable, the API also supports a chunked upload mode, where you make multiple requests with portions of the file. This is available in MediaWiki version 1.20 and above, although prior to version 1.25, SVGs could not be uploaded via chunked uploading. This is used by in browsers supporting FileAPI, uploading files in chunks of 1 megabyte, but you may choose your own size. This works in conjunction with the stash mode, to build a file up in pieces and then commit it at the end.

Étape n°1 : transmettre le contenu pour la première partie


For all the chunks except the last chunk you will receive this:

Étape n°2 : passer le paramètre filekey pour les morceaux suivants
You will obtain the  parameter from the previous continue result as well:



Pour le dernier morceau, vous recevrez ceci :

Étape n°3 : téléversement final utilisant filekey pour sauvegarder le téléversement hors de la zone temporaire


The result from the final upload will include the complete, accurate  object, comparable to what you would get from a non-chunked upload.

Erreurs possibles
See also the section on #Upload warnings above.

Historique des paramètres

 * v1.21:    ajouté
 * v1.19:      ajouté
 * v1.18:    ajouté
 * v1.17:,  ,  ,   ajouté
 * v1.18:  obsolète
 * v1.17:  obsolète

Notes supplémentaires

 * To check the status of an in-progress upload to the stash or the progress of a file being published from the stash, send a POST request:


 * Below is an example of a multipart POST to, representing a single chunk. Note that you must unstash the file for it to appear in the Wiki once you have successfully uploaded all your chunks.

User-Agent:  Content-Type: multipart/form-data; boundary=--24b7c3bb-fb4d-45c3-937c-11c2e0c2525b Host: commons.wikimedia.org Cookie: Connection: Keep-Alive

--24b7c3bb-fb4d-45c3-937c-11c2e0c2525b Content-Disposition: form-data; name="filename" Content-Length: 20

UploadTest356456.png --24b7c3bb-fb4d-45c3-937c-11c2e0c2525b Content-Disposition: form-data; name="offset" Content-Length: 1

0 --24b7c3bb-fb4d-45c3-937c-11c2e0c2525b Content-Disposition: form-data; name="format" Content-Length: 4

json --24b7c3bb-fb4d-45c3-937c-11c2e0c2525b Content-Disposition: form-data; name="ignorewarnings" Content-Length: 1

1 --24b7c3bb-fb4d-45c3-937c-11c2e0c2525b Content-Disposition: form-data; name="filesize" Content-Length: 3

971 --24b7c3bb-fb4d-45c3-937c-11c2e0c2525b Content-Disposition: form-data; name="token" Content-Length: 42

 --24b7c3bb-fb4d-45c3-937c-11c2e0c2525b Content-Disposition: form-data; name="stash" Content-Length: 1

1 --24b7c3bb-fb4d-45c3-937c-11c2e0c2525b Content-Disposition: form-data; name="chunk"; filename="1.png" Content-Type: application/octet-stream Content-Length: 971

 --24b7c3bb-fb4d-45c3-937c-11c2e0c2525b--

Voir aussi

 * - Permet à un utilisateur de se connecter
 * - Permet à un utilisateur d'importer une page
 * - Upload limits according to user groups