If you want to upload a file inside a Azure container, you can easily do it by using azure API's. The correct way to upload a file to azure container is to ensure always that the container is present or not.
So if you want to check that the container is available or not, please check this post.
blobClient.uploadFromFile(uploadPath + fileName);
this method takes your file path from local.
upload path can be : static String uploadPath = "data\\upload\\";
where data is a folder in your projecct root directory.
and file will be your file name present inside the path.
The method is :
public static void uploadFile(String containerName, String fileName) {
BlobServiceClient blobServiceClient = createBlobServiceClient();
BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(containerName);
BlobClient blobClient = containerClient.getBlobClient(fileName);
System.out.println("\nUploading to Blob storage as blob:\n\t" + blobClient.getBlobUrl());
blobClient.uploadFromFile(uploadPath + fileName);
}
Once this is done, you can ensure by listing files present inside the container and validate that your file is present inside it or not.
No comments:
Post a Comment