Get file
GET | /core/v1/{project}/{language}/file/{title}
|
---|
Returns information about a file, including links to download the file in thumbnail, preview, and original formats.
Examples
curl
# Get the file The_Blue_Marble.jpg on Wikimedia Commons
$ curl https://api.wikimedia.org/core/v1/commons/file/File:The_Blue_Marble.jpg
Python
# Python 3
# Get the file The_Blue_Marble.jpg on Wikimedia Commons
import requests
file = 'File:The_Blue_Marble.jpg'
url = 'https://api.wikimedia.org/core/v1/commons/file/' + file
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
PHP
<?php
// Get the file The_Blue_Marble.jpg on Wikimedia Commons
$url = 'https://api.wikimedia.org/core/v1/commons/file/File:The_Blue_Marble.jpg';
$authorization = 'Authorization: Bearer YOUR_ACCESS_TOKEN';
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( $authorization ));
curl_setopt( $ch, CURLOPT_USERAGENT, 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)' );
$output = curl_exec( $ch );
curl_close( $ch );
echo( $output );
?>
JavaScript
// Get the file The_Blue_Marble.jpg on Wikimedia Commons
let url = 'https://api.wikimedia.org/core/v1/commons/file/File:The_Blue_Marble.jpg';
let response = await fetch( url,
{
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Api-User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}
}
);
response.json()
.then(console.log).catch(console.error);
Parameters
project
required path |
Project name. For example: wikipedia (encyclopedia articles), commons (images, audio, and video), wiktionary (dictionary entries). List all projects.
|
language
required path |
Language code. For example: ar (Arabic), en (English), es (Spanish). List supported languages.
|
title
required path |
File title |
Responses
200 | Success: file found. Returns a file.
Example
{
"title": "The Blue Marble.jpg",
"file_description_url": "//commons.wikimedia.org/wiki/File:The_Blue_Marble.jpg",
"latest": {
"timestamp": "2011-12-07T05:11:41Z",
"user": {
"id": 811185,
"name": "Ultimate Roadgeek"
}
},
"preferred": {
"mediatype": "BITMAP",
"size": null,
"width": 599,
"height": 599,
"duration": null,
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/78/The_Blue_Marble.jpg/599px-The_Blue_Marble.jpg"
},
"original": {
"mediatype": "BITMAP",
"size": 7011595,
"width": 3000,
"height": 3002,
"duration": null,
"url": "https://upload.wikimedia.org/wikipedia/commons/7/78/The_Blue_Marble.jpg"
},
"thumbnail": {
"mediatype": "BITMAP",
"size": null,
"width": 1023,
"height": 1024,
"duration": null,
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/78/The_Blue_Marble.jpg/1023px-The_Blue_Marble.jpg"
}
}
|
---|---|
404 | Error: File not found
Example
{
"messageTranslations": {
"en": "The specified title does not exist"
},
"httpCode": 404,
"httpReason": "Not Found"
}
|