Upload a file
This method allows you to upload a file. The file will be stored in the server and will be available for download once it has been processed.
POST
/file
Examples
POST /file HTTP/1.1
Host: api.smsfactor.com
curl --location --request POST 'https://api.smsfactor.com/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.smsfactor.com/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.smsfactor.com/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.smsfactor.com/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.smsfactor.com/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
Result Format
{
"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>