отправить файл с Микротика методом POST
Добавлено: 15 ноя 2018, 11:04
Кто может подсказать как отправить файл с Микротика на Интернет ресурс методом POST с помощью команды /tool fetch ?
Конкретно интересует отправка вот на этот ресурс https://www.newocr.com/api/ по таким правилам:
Upload Files
You can upload JPEG, PNG, GIF, BMP and multipage TIFF, PDF, DJVU files.
To use multipart upload, make a POST request to the method's /v1/upload URI and add the query parameter key=api_key, for example:
POST /v1/upload?key=api_key HTTP/1.1
Host: api.newocr.com
Content-Type: multipart/form-data; boundary=---------------------------41184676334
Content-Length: 29278
-----------------------------41184676334
Content-Disposition: form-data; name="file"; filename="filename.jpg"
Content-Type: image/jpeg
(Binary data not shown)
-----------------------------41184676334--
If the request succeeds, the server returns the HTTP 200 OK status code along with any metadata:
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"data":
{
"file_id": "6fa11ac55c10ade5dd4d6126c34d1e08",
"pages": 257
}
}
Example: Curl upload
curl -H "Expect:" -F file=@./path/to/file http://api.newocr.com/v1/upload?key=api_key
Example: PHP upload
<?php
$file = realpath('filename.tif');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.newocr.com/v1/upload?key=api_key');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => '@'.$file));
$result = curl_exec($ch);
echo $result;
curl_close ($ch);
?>
Конкретно интересует отправка вот на этот ресурс https://www.newocr.com/api/ по таким правилам:
Upload Files
You can upload JPEG, PNG, GIF, BMP and multipage TIFF, PDF, DJVU files.
To use multipart upload, make a POST request to the method's /v1/upload URI and add the query parameter key=api_key, for example:
POST /v1/upload?key=api_key HTTP/1.1
Host: api.newocr.com
Content-Type: multipart/form-data; boundary=---------------------------41184676334
Content-Length: 29278
-----------------------------41184676334
Content-Disposition: form-data; name="file"; filename="filename.jpg"
Content-Type: image/jpeg
(Binary data not shown)
-----------------------------41184676334--
If the request succeeds, the server returns the HTTP 200 OK status code along with any metadata:
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"data":
{
"file_id": "6fa11ac55c10ade5dd4d6126c34d1e08",
"pages": 257
}
}
Example: Curl upload
curl -H "Expect:" -F file=@./path/to/file http://api.newocr.com/v1/upload?key=api_key
Example: PHP upload
<?php
$file = realpath('filename.tif');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.newocr.com/v1/upload?key=api_key');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => '@'.$file));
$result = curl_exec($ch);
echo $result;
curl_close ($ch);
?>