Search code examples
azure-storagefile-renameazure-data-lake

How to rename a file in blob storage by using Azure Datalake Gen2 Rest API


I've try to do the following instruction of this document : LINK

I used SAS authentication and added this to request header "x-ms-rename-source" but i kept getting this error "403-AuthorizationPermissionMismatch". Doing fine with all others api method but this one seem really tricky. Does anyone have success rename a file or directory with this one ?


Solution

  • Instead of using SAS authentication, i used authorization headers. You can check it here.

    My request headers :

      DateTime now = DateTime.UtcNow;
      requestMessage.Headers.Add("x-ms-date", now.ToString("R", CultureInfo.InvariantCulture));
      requestMessage.Headers.Add("x-ms-version", "2018-11-09");
    
      //your source path you want to rename
      requestMessage.Headers.Add("x-ms-rename-source", renameSourcePath);
    
      //rename operation only accept authorize by shared key via header
      requestMessage.Headers.Authorization = AzureStorageAuthenticationHelper.GetAuthorizationHeader(
      StorageGen2AccountName, StorageGen2AccountKey, now, requestMessage);