Uploading data larget than 4KB using /tool/fetch HTTP put

Hi!

So i have a little script to backup configuration using /tool/fetch. Here it is.

export file=backup
:local data [/file/get backup.rsc contents]
/tool/fetch url=http://host:8000/backups/upload http-method=post http-header-field="Authorization:authfieldvalue" http-data=$data

It is stored in /system/script.
And when I invoke it, I have a problem = data variable is empty. I’ve read that variable size is limited by 4KB. However, in one post on this forum I also read, that it was (at some moment in time) send more data (64KB or something like that) and in example I saw a parameter

http-content-type="application/json"

. But I cannot find this parameter in current routeros (7.11). This parameter is also present in documentation on mikrotik documentation website, but only in examples, not in parameters list.

Is there any way to POST an HTTP request, which contains a backup file contents (which is more than 4KB)?

In V7, variables should be 64KB, so I don’t think that’s the problem.

I suspect if you use the following instead (replacing “authfieldvalue” as needed):

http-header-field="Content-Type:application/json,Authorization:authfieldvalue"

I was going to say http-content-type=“application/json” looks like a ChatGPT hallucination, since it’s not valid syntax.
But OP is not wrong – it is in the docs ( https://help.mikrotik.com/docs/display/ROS/Fetch#Fetch-Sendinginformationtoaremotehost ):

Sending information to a remote host
It is possible to use an HTTP POST request to send information to a remote server, that is prepared to accept it. In the following example, we send geographic coordinates to a PHP page:

/tool fetch http-method=post > http-content-type> =“application/json” http-data=“{"lat":"56.12","lon":"25.12"}” url="> https://testserver.lv/index.php> "

But I think doc example is WRONG. There is NO “http-content-type=” as an option to /tool/fetch – at least in 7.12beta (or before AFAIK). So try the http-header-field= method since I know that works.

NO, if is used “/file content” is still 4k…

http://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/70

http://forum.mikrotik.com/t/max-size-of-variables-still-at-4096-anwser-is-no/168007/2

Fair enough, there may be multiple problems.

The http-content-type= is in docs, but not valid syntax in /tool/fetch… That’s what caught my eye here.

On the wiki is
http-header-field=“Content-Type: application/json”

The wiki is longer the docs :wink:. At help.mikrotik.com, they show this:

/tool fetch http-method=post http-content-type="application/json" http-data="{\"lat\":\"56.12\",\"lon\":\"25.12\"}" url="https://testserver.lv/index.php"

I know, I know, I’ve seen it… lacks quality control even on the new guide…

However the solution is much simpler: if @zetdotpi send them via ftp or via email and solve there…

PS: why change content type???
The export is not json…

I suppose that's the way I'll have to do it. :slight_smile: Uploading vua FTP and then processing with some scripts or something. I wanted to push backup via HTTP mainly to keep most of functionality in one server-side app.

PS: why change content type???
The export is not json....

Well, no real reason here. Just thought that maybe this http-content-type parameter can somehow affect variable size or something.
Mikrotik documentation is somewhat lacking and sometimes there are undocumented functions and behaviour.

They did fix the docs. The 4K upload limit has not changed.

I’ve used email to get files off RouterOS for a long while, and use a dedicated “RouterOS mailbox” as both the to and from. It works pretty well since email account becomes the “backup server”, with subject line have the router name/etc, already organized by date/time, etc. And if additional backup is needed IMAP can fetch to desktop etc., or you can use some script/code to connect to “routeros” mailbox to get any needed backups for further processing. Still be same “push” to your datacenter, just via SMTP not HTTP.

Upload via FTP and then use HTTP request without backup body to trigger event in service that backup file is uploaded.