Forum Discussion

Grant_Joy_24163's avatar
Grant_Joy_24163
Icon for Altostratus rankAltostratus
Sep 27, 2016

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"

 

4 Replies

  • 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'
    

     

  • 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 -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'

     

    • JRahm's avatar
      JRahm
      Icon for Admin rankAdmin

      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.

       

  • 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