Appending an empty file from local machine to ADLSGen2 Storage's file.

J, Praveen Kumar 1 Reputation point
2020-07-08T14:49:44.147+00:00
  1. Does it make sense to append an empty file to an existing file in Azure Data Lake Storage Gen2?

I have a csv file in Azure Data Lake Storage Gen2, I'm trying to append data to the same via REST API Call. In one of the scenario the data to be appended is empty. ie, 0 length data has to appended.

Is there any issue with the appending empty file? or Null probably via REST API?

Could you please give me a sample REST API syntax for the same.

Azure Data Lake Storage
Azure Data Lake Storage
An Azure service that provides an enterprise-wide hyper-scale repository for big data analytic workloads and is integrated with Azure Blob Storage.
1,410 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ChiragMishra-MSFT 956 Reputation points
    2020-07-09T12:05:39.367+00:00

    Hi @JPraveenKumar-4487,

    There shouldn't be a problem inserting content with 0 length.

    A simple way to use ADLS Gen2 APIs (Using OAuth2) to create a file would be :

    1. Acquire an Access token by making a POST request to https://login.microsoftonline.com/\<tenant id>/oauth2/v2.0/token Headers : "Content-Type: application/x-www-form-urlencoded" Body : {"client_id": <CLIENT_ID>, "client_secret": <CLIENT_SECRET>, "scope" : "https://storage.azure.com/.default", "grant_type" : "client_credentials" }
    2. Create a file system by making a PUT request to https://<storage account name>.dfs.core.windows.net/<file system name>?resource=filesystem Headers : Content-Length : 0 "x-ms-version":"2018-11-09" Authorization : Bearer <access_token from step1>
    3. Set default permissions on the root directory by making a PATCH request to https://<storage account name>.dfs.core.windows.net/<file system name>?action=setAccessControl Headers : Content-Length : 0 "x-ms-version":"2018-11-09" Authorization : Bearer <access_token from step1> x-ms-acl :
      user::rwx,group::r-x,other::--x,default:user::rwx,default:group::r-x,default:other::--
    4. Create a directory by making a PUT request to https://<storage account name>.dfs.core.windows.net/<file system name>/<directory name>?resource=directory Headers : Content-Length : 0 "x-ms-version":"2018-11-09" Authorization : Bearer <access_token from step1>
    5. Create a file by making a PUT request tohttps://<storage account name>.dfs.core.windows.net/<file system name>/<directory name>/<file
      name>?resource=file Headers : Content-Length : 0 "x-ms-version":"2018-11-09" Authorization : Bearer <access_token from step1>

    For more details, please refer this MSDN thread.

    Hope this helps.