Upload in Java to Azure storage, This is a memo to download.
Details will be investigated and added.
pom.xml
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>5.5.0</version>
</dependency>
java
public static final String storageConnectionString = "DefaultEndpointsProtocol=http;" +
"AccountName=[AccountName];" +
"AccountKey=[AcountKey]";
java
//Upload processing
private static void upload() throws Exception{
CloudBlobContainer container = auth();
//Upload processing
File file = new File("[Upload file path]");
FileInputStream fis = new FileInputStream(file);
CloudBlockBlob blockBlob = container.getBlockBlobReference(file.getName());
blockBlob.upload(fis, file.length());
fis.close();
}
java
//Download processing
private static void download() throws Exception{
CloudBlobContainer container = auth();
//Download processing
String uploadName = "[Download file name]";
CloudBlockBlob blockBlob = container.getBlockBlobReference(uploadName);
String downloadPath = "[Download file path]";
FileOutputStream fos = new FileOutputStream(new File(downloadPath));
blockBlob.download(fos);
fos.close();
}
If you execute it as it is, it will time out, so You need to set proxy in jvm. Specify the following parameters and execute.
option
-Dhttp.proxyHost=[proxyHost] -Dhttp.proxyPort=[proxyPort]
Recommended Posts