Upload un fichier
Cette méthode vous permet de télécharger un fichier. Le fichier sera stocké sur le serveur et pourra être téléchargé une fois qu'il aura été traité.
POST
/file
Exemples
POST /file HTTP/1.1
Host: api.smsup.ch
curl --location --request POST 'https://api.smsup.ch/file' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer your.token' \
--form 'file=@"/path/to/your/file"'
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.smsup.ch/file',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('file'=> new CURLFILE('/path/to/your/file')),
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Bearer your.token'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
var request = require('request');
var fs = require('fs');
var options = {
'method': 'POST',
'url': 'https://api.smsup.ch/file',
'headers': {
'Accept': 'application/json',
'Authorization': 'Bearer your.token'
},
formData: {
'file': {
'value': fs.createReadStream('/path/to/your/file'),
'options': {
'filename': 'IMG_20211206_231117.jpg',
'contentType': null
}
}
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
url = "https://api.smsup.ch/file"
payload={}
files=[
('file',('filename',open('/path/to/your/file','rb'),'mime/type'))
]
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer your.token'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
require "uri"
require "net/http"
url = URI("https://api.smsup.ch/file")
http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer your.token"
form_data = [['file', File.open('/path/to/your/file')]]
request.set_form form_data, 'multipart/form-data'
response = http.request(request)
puts response.read_body
Format de la réponse
{
"status": 1,
"message": "OK",
"file_id": "8681bdd0428ef9d0",
"filename": "file.jpg"
}
<response>
<status>1</status>
<message>OK</message>
<file_id>73100ea2aefd656d</file_id>
<filename>file.jpg</filename>
</response>