jsonazureazure-storageazure-file-share

Set-AzStorageFileContent saves strange line breaks


I have a json file, C:\temp\A.json:

[
    {
        "key": "value"
    }
]

I save this file to an Azure file share using this command:

Set-AzStorageFileContent -Context $SA.Context -ShareName $ShareName -Source C:\Temp\A.json -Path 'A.json'

This is what the file looks like in the storage account:

"[\r\n    {\r\n        \"key\": \"value\"\r\n    }\r\n]"

Why is this happening? What can I do to have the same line breaks as in the original file?


Solution

  • Set-AzStorageFileContent saves strange line breaks

    Initially, I tried with same command and got the same output in my environment.

    Portal:

    enter image description here

    The above scenario which file is being uploaded with Windows-style line endings. This is why the uploaded file shows \r\n characters.

    In the PowerShell command, there is no -Content-type parameter to accomplish this.

    So alternatively, I would suggest you use Azure CLI command to upload as json file by adding --content-type application/json in the command.

    Command and Output:

    PS C:\Users\v-vsettu> az storage file upload --account-key "xxxxxPSCqF2MmpB+AStyKyulA==" --account-name "venkat32612" --path "A.json" --share-name "share1" --source "C:\Users\xx-xx\vxx\oxx\file.json" --content-type application/json
    Finished[#############################################################]  100.0000%
    {
      "content_md5": "0xexxxxxx0x5c0x270x65",
      "date": "2024-06-18T06:29:17+00:00",
      "etag": "\"0xxxE3C0C\"",
      "file_last_write_time": "2024-06-18T06:29:17.4349836Z",
      "last_modified": "2024-06-18T06:29:17+00:00",
      "request_id": "d07dfabxxxx2a3d000000",
      "request_server_encrypted": true,
      "version": "2022-11-02"
    }
    

    enter image description here

    Portal: enter image description here

    Reference:

    az storage file | Microsoft Learn