11-Jan-2018 04:25
Hello Everyone,
My GET request to the device is https://192.168.55.248/mgmt/tm/asm/file-transfer/downloads/exported_file.xml
And the error I receive is,
{ "code": 400, "message": "Requested file size 3165860 greater than maximum chunk size 1048576 allowed", "referer": "172.16.26.16", "restOperationId": 14388536, "kind": ":resterrorresponse" }
I am able to transfer the file via SCP. Is there any workaround to download the same via API? Please confirm.
16-Jan-2018
16:04
- last edited on
05-Jun-2023
13:20
by
JimmyPackets
I can think of one workaround.
/mgmt/shared/iapp/file-management/
allows you to download a file under the /var/config/rest/iapps/
directory, however, the feature (API) is only available on 13.1.0 or later. For example, to download /var/config/rest/iapps/sat/sat.txt
:
curl https:///mgmt/shared/iapp/file-management/sat/sat.txt
You can use the
/mgmt/tm/util/bash
endpoint and execute cat
command, however, you need to cleanse the response as the file content is JSON formatted: e.g.,
curl https:///mgmt/tm/util/bash \
-X POST -H "Content-Type: application/json" \
-d "{\"command\":\"run\", \"utilCmdArgs\": \"-c 'cat /tmp/sat.txt'\"}"
The response looks like this (The bold part is the file content: 5 lines of text. Note that LF is represented as the literal \n (0x5c 0x6e)):
{"kind":"tm:util:bash:runstate","command":"run","utilCmdArgs":"-c 'cat /tmp/sat.txt'","commandResult":"Line 1\nLine 2\nLine 3\nLine 4\nLine 5\n"}
21-Jan-2018
13:00
- last edited on
05-Jun-2023
13:19
by
JimmyPackets
The maximum octets you can download using the
/mgmt/tm/asm/file-transfer/downloads/file
endpoint is 1,048,576 bytes (1 MiB = 1,0242). Any remaining data is silently truncated (I did not get the 400 error you got. Possibly version dependent. Mine was 13.0.0).
When you need to download a file larger than this limit, download chunk by chunk by using the
Content-Range
header. For example, to download a 3,165,860 bytes file, use the REST call three times.
GET /mgmt/tm/asm/file-transfer/downloads/file > file ... first 1 MiB
GET /mgmt/tm/asm/file-transfer/downloads/file -H "Content-Range: 1048576-2097151/3165860"
>> file ... next 1 MiB
GET /mgmt/tm/asm/file-transfer/downloads/file -H "Content-Range: 2097152-3165860/3165860" >> file ... the remaining octets
See also Demystifying iControl REST Part 5: Transferring Files for the Content-Range header format.
29-Jul-2019 21:03
Isn't "Content-Range" issued by the server? The client side should use "Range:" instead in its request.
29-Jul-2019 21:51
It is implemented that way presently. F5 is aware of the discrepancy with RFC 7233 and has a bug ID assigned to the issue: ID701702.
15-Jul-2019 15:57
after receiving this file how can be store it to read it? does storing in *.txt format work ?
29-Jul-2019 22:49
That clears it up. Thanks!
21-Jul-2019 18:57
As shown above, >> (double redirect) should append the data (HTTP response) to the file. If you are using curl, -o (hyphen o) option is also handy.
Regarding the file extension, it depends on the type of file (data) you download. If you are downloading an jpeg image, then its' natural to add the .jpg extension to the filename and open with an image viewer (although Unix does not rely upon file extensions, I personally prefer to add appropriate one). If the data is text, yes, use .txt and open with an text editor of your choice.
29-Jul-2019 17:32
Related question: