question

ChihHaoHuang-7892 avatar image
0 Votes"
ChihHaoHuang-7892 asked ChihHaoHuang-7892 commented

Azure File Service REST API(rename)

Hi,
Followed this document https://docs.microsoft.com/en-us/rest/api/storageservices/rename-file to send rename request.
But it didn't work.
Also in the document, the header x-ms-file-rename-source:name seems a typo.
Send request with this header will get 403.

Send request with header x-ms-file-rename-source-name will pass authorization but will get
InternalError (500): Server encountered an internal error. Please try again after some time.

I am using SharedKey authentication. Other requests like get file or set metadata works fine.
I suppose there is something wrong with the API endpoint.

azure-files
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ChihHaoHuang-7892 Thank you for reaching out to Microsoft Q&A.

I see that the file Rename request gives error 403 when using share key authentication. Please verify that the Date header includes time in UTC timestamp for the request as that may give a 403 error if the request seems older than 15 minutes for the Storage Service. Please find more details here.

Let me know if this helps. Looking forward to your response. Thank you!

Please let us know if you have any further questions and we will be glad to assist you further. Thank you!

Remember:

Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.

Want a reminder to come back and check responses? Here is how to subscribe to a notification.



0 Votes 0 ·

I am confirming the same issue with SAS token.
I use direct HTTPS PUT requests. Other fuctionality works (creating files, directories, put range). It means that it is not related to authorization.

With x-ms-file-rename-source I got "The value for one of the HTTP headers is not in the correct format."
With x-ms-file-rename-source-name I get Internal Error "Server encountered an internal error. Please try again after some time."

https://<storage_account>.file.core.windows.net/masterpack/branches.txt?comp=rename&<SAS_token>;

0 Votes 0 ·

The correct name of the header is most likely "x-ms-file-rename-source" as it is defined in the documentation.
See also some Azure sources: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/storage/Azure.Storage.Files.Shares/src/Generated/FileRestClient.cs

If you try to set any unknown header then you get Internal Error 500 "Server encountered an internal error. Please try again after some time.". Which is also a bug - there should be an error like "Unrecognized header".

Anyway renaming does not work
Error 400 on PUT to URL https://<censored>.file.core.windows.net/masterpack/branches.txt?comp=rename&<SAS_token_is_censored>; - The value for one of the HTTP headers is not in the correct format.:
?<?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:5241ea48-001a-007e-04b0-59490f000000
Time:2022-04-26T20:57:33.7173281Z</Message><HeaderName>x-ms-file-rename-source</HeaderName><HeaderValue>branches.txt.temp</HeaderValue></Error>


0 Votes 0 ·

1 Answer

KonshinAlex-4448 avatar image
0 Votes"
KonshinAlex-4448 answered ChihHaoHuang-7892 commented

I have finally solved the problem by looking at sources of Azure API Java SDK
https://github.com/Azure/azure-sdk-for-java/blob/a6afd5ca8c476ae32ba7f3e5f19d288c4eb4f6bf/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/implementation/FilesImpl.java#L1338

It is just purely documented x-ms-file-rename-source. In the sources we can see that the value should be "the URI-style path of the source file, up to 2 KB in length."
In caseof SAS authentication the URI should include SAS token as well.

This must be written in the documentation for Rename File request in REST API documentation! The current page contains very confusing explanation and has no any examples.
https://docs.microsoft.com/en-us/rest/api/storageservices/rename-file

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I can confirm this works.
I use shared key, so the value of x-ms-file-rename-source is the URL of the source file.

0 Votes 0 ·

Rename a file works but rename a directory got Azure::Core::Http::HTTPError (InvalidHeaderValue (400): The value for one of the HTTP headers is not in the correct format.)
Checked the code for directory, looks like x-ms-file-rename-source should be an URI as well.
But it didn't work

0 Votes 0 ·