none
Error while calling ADLS Gen 2 Rest API to flush file RRS feed

  • Question

  • I am trying to use the Rest API of Create path to create a file and flush uncommitted data in ADLS Gen 2. The below are the parameters used for calling the API.

    https://{accountName}.dfs.core.windows.net/{fileSystem}/{path}/{fileName}?action=append&position=0&timeout=1000

    headers:

    (Content-Length", 21)
    ("Content-Type", "text/plain")
    ("x-ms-date", sdf.format(new Date()) + " GMT")
    ("x-ms-version","2018-11-09")
    ("Authorization", "Bearer " + token)

    body="asdfadfsasdfadsfasdf\n"

    >>>I can got "Accepted" response when I executed above httpPatch(append) request.

    >>>Then I execute below httpPatch(flush) request, I got an Error----"HTTP/1.1 400 The uploaded data is not contiguous or the position query parameter value is not equal to the length of the file after appending the uploaded data."

    https://{accountName}.dfs.core.windows.net/{fileSystem}/{path}/{fileName}?action=flush&position=21

    headers:

    ("Content-Length","0")

    ("Authorization", "Bearer " + token);

    >>>Please let me know if i am doing anything wrong with PATCH operation?


    • Edited by Terry_Wu Thursday, July 25, 2019 4:20 AM
    Thursday, July 25, 2019 4:02 AM

Answers

  • Hi Chirag,

    Thank u for your help.

    I have solved this error.

    This error may be occurred by wrong format of request body.

    At first, I used form (format) to set the string into body.  Error occurred.

    -------------------------------------------------------------------

    import okhttp3.RequestBody;

    import okhttp3.FormBody;

    Map<String, String> formParamMap = new HashMap<>();
    formParamMap.put("requestBody", requestBodyStr);
    final FormBody.Builder formBuilder = new FormBody.Builder();
    formParamMap.forEach(formBuilder::add);
    RequestBody requestBody = formBuilder.build();

    -------------------------------------------------------------------

    Now I use a simple way to set the string into body, and solved this error.

    -------------------------------------------------------------------

    import okhttp3.RequestBody;

    RequestBody requestBody = RequestBody.create(MediaType.parse("text/plain"), text, 0, text.length);

    -------------------------------------------------------------------

    Best regards

    Tuesday, July 30, 2019 7:27 AM

All replies

  • Hi Terry,

    The string that you are sending is of length 22 (it counts '\' also as a character). Hence you will have to modify the Content-length to 22 in the append step and the position to 22 in the flush step.

    Hope this helps.

    Thursday, July 25, 2019 9:12 AM
    Moderator
  • Hi Chirag

    Thank u for your response.

    I am sorry to mislead you.

    "\n" is a line Break(EOF)which I found it in debug model.

    The string in file is "asdfadfsasdfadsfasdf".

    I got the file length info by below code.

    -----------------------------------------------------------------------------------------------

    String requestBodyStr = getFileString(fileFolder + "/" + fileName);

    String requestLength = String.valueOf(requestBodyStr.getBytes(Charset.forName("UTF-8")).length);

    -----------------------------------------------------------------------------------------------

    Could u please refer below screen shot.(debug model/ parameter detail)

    Best Regards



    • Edited by Terry_Wu Friday, July 26, 2019 12:34 AM
    Thursday, July 25, 2019 11:49 PM
  • Hi Terry,

    The way an escape character is read is subjective to the programming language used. Hence, it cannot be affirmed that the "length" would give you the exact no. of characters.

    Escape characters might be treated differently in ADLS. Hence I would recommend you to remove such special characters and then try.

    Hope this helps.

    Monday, July 29, 2019 7:24 AM
    Moderator
  • Hi Chirag,

    Thank u for your help.

    I have solved this error.

    This error may be occurred by wrong format of request body.

    At first, I used form (format) to set the string into body.  Error occurred.

    -------------------------------------------------------------------

    import okhttp3.RequestBody;

    import okhttp3.FormBody;

    Map<String, String> formParamMap = new HashMap<>();
    formParamMap.put("requestBody", requestBodyStr);
    final FormBody.Builder formBuilder = new FormBody.Builder();
    formParamMap.forEach(formBuilder::add);
    RequestBody requestBody = formBuilder.build();

    -------------------------------------------------------------------

    Now I use a simple way to set the string into body, and solved this error.

    -------------------------------------------------------------------

    import okhttp3.RequestBody;

    RequestBody requestBody = RequestBody.create(MediaType.parse("text/plain"), text, 0, text.length);

    -------------------------------------------------------------------

    Best regards

    Tuesday, July 30, 2019 7:27 AM
  • Glad that the issue was resolved Terry.
    Tuesday, July 30, 2019 9:22 AM
    Moderator