I’m trying to upload a file to ADLS Gen2 storage with Microsoft Entra ID(Service Principal) Authorization.
Getting below error message while uploading a file to ADLS gen2 using DataLakeServiceClient
com.azure.storage.file.datalake.models.DataLakeStorageException: Status code 400, “?MissingRequiredHeader
An HTTP header that’s mandatory for this request is not specified.
RequestId:adad-dads-d-20a2-xxdadad
Time:2024-05-07T17:18:58.0750289Zx-ms-type
DataLakeServiceClient dataLakeServiceClient = new DataLakeServiceClientBuilder()
.endpoint("https://<storageaccount>.file.core.windows.net/")
.credential(new ClientSecretCredentialBuilder()
.clientId("<client_id>")
.clientSecret("<client_secret>")
.tenantId("<tenantId>")
.build()).buildClient();
DataLakeFileSystemClient container = dataLakeServiceClient.getFileSystemClient("test");
DataLakeDirectoryClient directoryClient = container.getDirectoryClient("upload").getSubdirectoryClient("customer_info");
InputStream stream = new ByteArrayInputStream("hello".getBytes(StandardCharsets.UTF_8));
long fileLength;
try {
fileLength = stream.available();
DataLakeFileClient fileClient = directoryClient.createFileIfNotExists("test.csv");
//fileClient.cr
fileClient.upload(stream, fileLength);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
POM.xml
`<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-file-datalake</artifactId>
<version>12.18.3</version>
</dependency>
`