none
Uploading a File to Azure Storage Account using cURL / REST API does not work

    Question

  • Hi,

    I have the following issue when I try to upload a file to azure storage using REST API in a LINUX VM using cURL.

    Any idea what the issue could be?

    My expertise level is BEGINNER.

    curl -H "x-ms-version:2015-02-21" -H "x-ms-type:File" -vX PUT 'https://xxxxxxxxxxxxxxxxxxxxxx.file.core.windows.net/enp-core-sftp/landing/enp/account/scheduling-design_v3.pdf?sv=2015-12-11&ss=bfqt&srt=sco&sp=rwdlacup&se=2017-12-31T20:27:54Z&st=2017-01-18T12:27:54Z&spr=https&sig=xxxxxxxxxxxxxxxxxxxxxx' --data-binary @downloaded.pdf

    ERROR RESPONSE:

    * About to connect() to xxxxxxxxxxxxxxxxxxxxxx.file.core.windows.net port 443 (#0)
    *   Trying 104.208.248.28...
    * Connected to xxxxxxxxxxxxxxxxxxxxxx.file.core.windows.net (104.208.248.28) port 443 (#0)
    * Initializing NSS with certpath: sql:/etc/pki/nssdb
    *   CAfile: /etc/pki/tls/certs/ca-bundle.crt
      CApath: none
    * SSL connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
    * Server certificate:
    *       subject: CN=*.file.core.windows.net
    *       start date: Jul 02 06:17:59 2016 GMT
    *       expire date: May 07 17:03:30 2018 GMT
    *       common name: *.file.core.windows.net
    *       issuer: CN=Microsoft IT SSL SHA2,OU=Microsoft IT,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US
    > PUT /enp-core-sftp/landing/enp/account/scheduling-design_v3.pdf?sv=2015-12-11&ss=bfqt&srt=sco&sp=rwdlacup&se=2017-12-31T20:27:54Z&st=2017-01-18T12:27:54Z&spr=https&sig=xxxxxxxxxxxxxxxxxxxxxx HTTP/1.1
    > User-Agent: curl/7.29.0
    > Host: xxxxxxxxxxxxxxxxxxxxxx.file.core.windows.net
    > Accept: */*
    > x-ms-version:2015-02-21
    > x-ms-type:File
    > Content-Length: 122289
    > Content-Type: application/x-www-form-urlencoded
    > Expect: 100-continue
    >
    < HTTP/1.1 400 The value for one of the HTTP headers is not in the correct format.
    < Content-Length: 326
    < Content-Type: application/xml
    < Server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0
    < x-ms-request-id: 4a38fe16-001a-00b9-49c7-71cff2000000
    < x-ms-version: 2015-02-21
    < Date: Wed, 18 Jan 2017 20:14:33 GMT
    * HTTP error before end of send, stop sending
    <
    <?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidHeaderValue</Code><Message>The value for one of the HTTP headers is not in the correct format.
    RequestId:4a38fe16-001a-00b9-49c7-71cff2000000
    * Closing connection 0
    Time:2017-01-18T20:14:34.7421836Z</Message><HeaderName>Content-Length</HeaderName><HeaderValue>122289</HeaderValue></Error>

    The size of downloaded.pdf file is 122289 (wc -c < downloaded.pdf)

    When I run the same cURL script with zero content-length specified it works but uploads a zero-byte file.

    curl -H "Content-Length:0" -H "Content-Type:application/binary" -H "x-ms-version:2015-02-21" -H "x-ms-type:File" -H "x-ms-content-length:0" -vX PUT 'https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.file.core.windows.net/enp-core-sftp/landing/enp/account/scheduling-design_v3.pdf?sv=2015-12-11&ss=bfqt&srt=sco&sp=rwdlacup&se=2017-12-31T20:27:54Z&st=2017-01-18T12:27:54Z&spr=https&sig=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' --data-binary @downloaded.pdf

    SUCCESS RESPONSE BUT WITH ZERO BYTE FILE:

    * About to connect() to xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.file.core.windows.net port 443 (#0)
    *   Trying 104.208.248.28...
    * Connected to xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.file.core.windows.net (104.208.248.28) port 443 (#0)
    * Initializing NSS with certpath: sql:/etc/pki/nssdb
    *   CAfile: /etc/pki/tls/certs/ca-bundle.crt
      CApath: none
    * SSL connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
    * Server certificate:
    *       subject: CN=*.file.core.windows.net
    *       start date: Jul 02 06:17:59 2016 GMT
    *       expire date: May 07 17:03:30 2018 GMT
    *       common name: *.file.core.windows.net
    *       issuer: CN=Microsoft IT SSL SHA2,OU=Microsoft IT,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US
    > PUT /enp-core-sftp/landing/enp/account/scheduling-design_v3.pdf?sv=2015-12-11&ss=bfqt&srt=sco&sp=rwdlacup&se=2017-12-31T20:27:54Z&st=2017-01-18T12:27:54Z&spr=https&sig=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx HTTP/1.1
    > User-Agent: curl/7.29.0
    > Host: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.file.core.windows.net
    > Accept: */*
    > Content-Length:0
    > Content-Type:application/binary
    > x-ms-version:2015-02-21
    > x-ms-type:File
    > x-ms-content-length:0
    > Expect: 100-continue
    >
    < HTTP/1.1 201 Created
    < Transfer-Encoding: chunked
    < Last-Modified: Wed, 18 Jan 2017 20:21:47 GMT
    < ETag: "0x8D43FDFA0B383C8"
    < Server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0
    < x-ms-request-id: c26de9d0-001a-004d-3fc8-71ea1e000000
    < x-ms-version: 2015-02-21
    < Date: Wed, 18 Jan 2017 20:21:47 GMT
    <
    * Connection #0 to host xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.file.core.windows.net left intact





    Wednesday, January 18, 2017 8:34 PM

All replies

  • Hi,

    Thank you for contacting Microsoft forums. We are pleased to answer your query.

    We are checking on the query and will get back to you soon on this. I apologize for the inconvenience and appreciate your time and patience in this matter.

    Regards,

    Vikranth S.

    Thursday, January 19, 2017 2:53 PM
    Moderator
  • Hello,

     

    Do you want to try to see if specifying the x-ms-content-length helps?

    x-ms-content-length: byte value

    Required. This header specifies the maximum size for the file, up to 1 TB.

     

    Also, please ensure Content-Length is 0

    Content-Length

    Optional. Must be zero if present.

     

    Reference: https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/create-file

    I hope that the reply will assist you in getting your query addressed. In case you require further assistance, please do reply to the thread as we are always available to your queries.

     

     

    Regards,

    Vikranth S.

     

    Kindly click "Mark as Answer" on the post that helps you, this can be beneficial to other community members reading the thread. And Vote as Helpful.

     


    Sunday, January 22, 2017 12:34 PM
    Moderator