Forum Discussion
Error code 400 while downloading a file via REST API
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.
- Arindam_MajumdeAltocumulus
after receiving this file how can be store it to read it? does storing in *.txt format work ?
- JGCumulonimbus
That clears it up. Thanks!
- Satoshi_Toyosa1Ret. Employee
Related question:
- Satoshi_Toyosa1Ret. Employee
I can think of one workaround.
allows you to download a file under the/mgmt/shared/iapp/file-management/
directory, however, the feature (API) is only available on 13.1.0 or later. For example, to download/var/config/rest/iapps/
:/var/config/rest/iapps/sat/sat.txt
curl https:///mgmt/shared/iapp/file-management/sat/sat.txt
You can use the
endpoint and execute/mgmt/tm/util/bash
command, however, you need to cleanse the response as the file content is JSON formatted: e.g.,cat
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"}
- Satoshi_Toyosa1Ret. Employee
The maximum octets you can download using the
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)./mgmt/tm/asm/file-transfer/downloads/file
When you need to download a file larger than this limit, download chunk by chunk by using the
header. For example, to download a 3,165,860 bytes file, use the REST call three times.Content-Range
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.
- JGCumulonimbus
Isn't "Content-Range" issued by the server? The client side should use "Range:" instead in its request.
- Satoshi_Toyosa1Ret. Employee
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.
- Satoshi_Toyosa1Ret. Employee
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.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com