none
Creating a file via the Data Lake Gen2 REST API results in a blank file.

    Question

  • I'm trying to upload a file using the Gen2 REST API Path - Create endpoint.

    I send a PUT request to https://myaccount.dfs.core.windows.net/myfilesystem/json-file.json?resource=file

    With the following headers:

    x-ms-version:2018-11-09
    Content-Length:0
    Content-Type:application/json

    And this simple JSON string as the body

    {
    "name": "John"
    }

    The API responds with 201 Created and I do see the file in the Storage Explorer. But when I download it, it's 0 bytes, empty.

    What am I missing?



    • Edited by eparizzi Monday, May 6, 2019 6:18 PM
    Monday, May 6, 2019 6:18 PM

All replies

  • Please use these two call to write to a file , the one which you used as creates a file resource .

    The following command adds text to the beginning of file1.

    printf 'data row 1\ndata row 2\n' | curl -i -X PATCH -H "x-ms-version: 2018-11-09" -H "Authorization: Bearer $ACCESS_TOKEN" --data-binary @- "https://$STORAGE_ACCOUNT_NAME.dfs.core.windows.net/mydata/data/file1?action=append&position=0"

    Once complete, the server returns a 202 Accepted response.

    With existing data already in file1, the following command appends data to the existing value.

    printf 'data row 3\ndata row 4\n' | curl -i -X PATCH -H "x-ms-version: 2018-11-09" -H "Authorization: Bearer $ACCESS_TOKEN" --data-binary @- "https://$STORAGE_ACCOUNT_NAME.dfs.core.windows.net/mydata/data/file1?action=append&position=22"

    Once complete, the server returns a 202 Accepted response.

    At this point, the text sits in an uncommitted buffer on the server. To endure data to the file system, flush the file using the following command:

    curl -i -X PATCH -H "x-ms-version: 2018-11-09" -H "content-length: 0" -H "Authorization: Bearer $ACCESS_TOKEN" "https://$STORAGE_ACCOUNT_NAME.dfs.core.windows.net/mydata/data/file1?action=flush&position=44"

    Once complete, the server returns a 200 OK response.


    Thanks Himanshu

    Wednesday, May 8, 2019 9:40 PM