Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

Unable to Upload File Through iControl REST Interface

I am attempting to upload a file through the iControl REST interface using iControl BIG-IP v12 getting a response code 400 with a response body of: {"remainingByteCount":0,"usedChunks":{"0":5},"totalByteCount":5,"localFilePath":"/var/config/rest/downloads/test.txt","temporaryFilePath":"/var/config/rest/downloads/tmp/test.txt","generation":0,"lastUpdateMicros":1475011484946186}

I am using token auth. I am at a loss as to why this is giving back a 200, any help would be greatly appreciated. I can answer any questions that will help give us clues.

Here are the headers that I have:

Content-Type: "text/plain"
Content-Range: "0-4/5"
Content-Length: "5"
Transfer-Encoding: "chunked"

And the response debug data:

server: "com.f5.rest.common.RestRequestSender"
x-frame-options: "SAMEORIGIN"
pragma: "no-cache"
cache-control: "no-store, no-cache, must-revalidate"
expires: "-1"
content-length: "231"
content-type: "text/plain; charset=ISO-8859-1"
content-range: "0-4/5"
local-ip-from-httpd: "xxx.xxx.xxx.xxx"
accept-encoding: "gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
x-forwarded-server: "localhost.localdomain"
x-forwarded-proto: "http"
x-forwarded-host: "xxx.xxx.com"
x-content-type-options: "nosniff"
x-xss-protection: "1; mode=block"
content-security-policy: "default-src 'self'  'unsafe-inline' 'unsafe-eval'"
strict-transport-security: "max-age=16070400; includeSubDomains"
connection: "close"
0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

From curl, you can do that this way (note the octet/stream content-type)

# Get the content length
jrahm@ubuntu:/var/tmp/le/config/certs/rahmen-empire.net$ wc -c cert.csr | awk '{print $1}'
1691

# Initiate the Upload
curl -i -sk -u admin:admin -X POST 
-H "Expect:" 
-H "Content-Type: application/octet-stream" 
-H "Content-Range: 0-1690/1691" 
--data-binary "@cert.csr"  
https://172.16.44.15/mgmt/shared/file-transfer/uploads/cert.csr

or if you wanted to use the f5-common-python sdk, it's pretty simple:

>>> from f5.bigip import ManagementRoot as mr
>>> import requests
>>> requests.packages.urllib3.disable_warnings()
>>> b = mr('172.16.15.201', 'admin', 'admin')
>>> b.shared.file_transfer.uploads.upload_file('/Users/rahm/test.txt')
>>> b.tm.util.bash.exec_cmd('run', utilCmdArgs='-c "cat /var/config/rest/downloads/test.txt"').commandResult
u'hello world\n'
1
Comments on this Answer
Comment made 12-Oct-2016 by Grant Joy 85

Thank you Jason. What I ended up using was Ruby. Token auth ended up not working quite as expected, so I gave up on it and used basic auth for every command.

My Ruby code ended up looking like this:

upload_file = Faraday::UploadIO.new "/path/to/file", 'text/plain'
file_size = File.size upload_file
path = "/mgmt/shared/file-transfer/uploads/#{file_name}"
result = connection.post path, upload_file do |req|
  req.headers['Content-Range'] = "0-#{file_size - 1}/#{file_size}"
  req.headers['Transfer-Encoding'] = 'chunked'
  req.headers['Content-Type'] = 'application/octet-stream'
end

Please see my other questions/answers for further insight into how I ended up getting all this working.

1
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hello, were anyone able to upload an image to F5 .iso?

I tried the following but none worked. I think b/c file is so big even though I set Transfer-Encoding to Chucked.

curl -X POST -i -k -v https://x.x.x.x/mgmt/cm/autodeploy/sotfware-image-uploads/BIGIP-13.0.0.0.0.1645.iso -H 'Authorization: Basic xxxxxxx' -H 'Transfer-Encoding: chunked' -H 'Content-Range: 0-1689118719/1689118720' -H 'Content-Type: application/octet-stream' -H 'Expect: ' --data-binary '@/Users/123930/Downloads/BIGIP-13.0.0.0.0.1645.iso'

0
Comments on this Answer
Comment made 3 months ago by Jason Rahm

you will need to break your file into manageable chunks to transfer, you can't send it all at once. I have a python example in this article, and someone posted a powershell example in the comments.

-1
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hello,

while using ansible and f5 modules to upload iso image to f5... it's failing with below trace. does not tell me much...

anyone able to upload image to F5 using ansible?

TASK [f5-upgrade : Upload BIG-IP image from user desktop to remote F5 node] ******************************************************************************** task path: /Users/123930/bitbucket/f5-automator/roles/f5-upgrade/tasks/main.yml:3 ESTABLISH LOCAL CONNECTION FOR USER: 123930 EXEC /bin/sh -c 'echo ~123930 && sleep 0' EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /Users/123930/.ansible/tmp/ansible-tmp-1547493023.37-56197678303710" && echo ansible-tmp-1547493023.37-56197678303710="echo /Users/123930/.ansible/tmp/ansible-tmp-1547493023.37-56197678303710" ) && sleep 0' Using module file /usr/local/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_software_image.py PUT /Users/123930/.ansible/tmp/ansible-local-60706uusZ3G/tmp8nlo9v TO /Users/123930/.ansible/tmp/ansible-tmp-1547493023.37-56197678303710/AnsiballZ_bigip_software_image.py EXEC /bin/sh -c 'chmod u+x /Users/123930/.ansible/tmp/ansible-tmp-1547493023.37-56197678303710/ /Users/123930/.ansible/tmp/ansible-tmp-1547493023.37-56197678303710/AnsiballZ_bigip_software_image.py && sleep 0' EXEC /bin/sh -c '/usr/local/opt/python@2/bin/python2.7 /Users/123930/.ansible/tmp/ansible-tmp-1547493023.37-56197678303710/AnsiballZ_bigip_software_image.py && sleep 0' EXEC /bin/sh -c 'rm -f -r /Users/123930/.ansible/tmp/ansible-tmp-1547493023.37-56197678303710/ > /dev/null 2>&1 && sleep 0' The full traceback is: WARNING: The below traceback may not be related to the actual failure. File "/var/folders/jy/z8zx4bdx6r78hh4c100gp3sr7vx3zm/T/ansible_bigip_software_image_payload_y5yQ4F/__main__.py", line 473, in main results = mm.exec_module() File "/var/folders/jy/z8zx4bdx6r78hh4c100gp3sr7vx3zm/T/ansible_bigip_software_image_payload_y5yQ4F/__main__.py", line 260, in exec_module changed = self.present() File "/var/folders/jy/z8zx4bdx6r78hh4c100gp3sr7vx3zm/T/ansible_bigip_software_image_payload_y5yQ4F/__main__.py", line 283, in present return self.create() File "/var/folders/jy/z8zx4bdx6r78hh4c100gp3sr7vx3zm/T/ansible_bigip_software_image_payload_y5yQ4F/__main__.py", line 358, in create self.create_on_device() File "/var/folders/jy/z8zx4bdx6r78hh4c100gp3sr7vx3zm/T/ansible_bigip_software_image_payload_y5yQ4F/__main__.py", line 387, in create_on_device "Failed to upload the file."

fatal: [f5_shipstg1_ext01 -> localhost]: FAILED! => { "changed": false, "invocation": { "module_args": { "auth_provider": null, "force": null, "image": "/Users/123930/Downloads/BIGIP-13.0.0.0.0.1645.iso", "password": null, "provider": { "auth_provider": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "server": "10.137.194.20", "server_port": null, "ssh_keyfile": null, "timeout": null, "transport": "rest", "user": "admin", "validate_certs": false }, "server": null, "server_port": null, "state": "present", "transport": null, "user": null, "validate_certs": null } }, "msg": "Failed to upload the file." } to retry, use: --limit @/Users/123930/bitbucket/f5-automator/playbooks/upload-image_playbook.retry

PLAY RECAP ************************************************************************************************************************************************* f5_shipstg1_ext01 : ok=1 changed=0 unreachable=0 failed=1

0