Java upload and download notes to Azure storage

Introduction

Upload in Java to Azure storage, This is a memo to download.

Details will be investigated and added.

jar installation (Maven)

pom.xml


    <dependency>
	    <groupId>com.microsoft.azure</groupId>
	    <artifactId>azure-storage</artifactId>
	    <version>5.5.0</version>
	</dependency>

Definition of authentication constant

java


	public static final String storageConnectionString = "DefaultEndpointsProtocol=http;" +
			"AccountName=[AccountName];" +
			"AccountKey=[AcountKey]";

upload

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();
    }

download

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();
    }

When running in a proxy environment

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

Java upload and download notes to Azure storage
Upload and download notes in java on S3
Android-Upload image files to Azure Blob Storage in Java
[Java] Upload images and base64
How to write and notes when migrating from VB to JAVA
Zip and upload multiple files to Firebase Storage on Android.
Let's create a file upload system using Azure Computer Vision API and Azure Storage Java SDK
[Note] Download from S3, upload to S3
[Java] Basic types and instruction notes
Notes on Java path and Package
Notes on building Kotlin development environment and migrating from Java to Kotlin
Upload multiple images to Cloudinary on Active Storage and publish to Heroku
Java implementation to create and solve mazes
java notes
[Java] How to output and write files!
[Java] Test S3 upload / download using "S3 ninja"
Add Document to Azure Search Service (Java)
Download and install Eclipse (Java) (Mac version)
[Introduction to Java] Variable declarations and types
Creating Java Web Applications to Azure Web Apps
Java to C and C to Java in Android Studio
[Java] Corrective notes for "Invalid escape character" and "Cannot map to encoding MS932"
Upsert from Java SDK to Azure Cosmos DB
Kotlin functions and lambdas to send to Java developers
[Java] How to use FileReader class and BufferedReader class
Review notes for Java 1.7 and later file copies
[Java] How to get and output standard input
Try to link Ruby and Java with Dapr
How to get and study java SE8 Gold
Java8 to start now ~ forEach and lambda expression ~
How to access Java Private methods and fields
Select * from Java SDK to Azure Cosmos DB
[Java] How to use Calendar class and Date class
Java Generics (Notes)
[Java] Array notes
[Java] Introduction to Java
Java and JavaScript
[Java] Study notes
XXE and Java
Java serialization notes
Introduction to java
<java> Read Zip file and convert directly to string
Convert Java enum enums and JSON to and from Jackson
[Java] Types of comments and how to write them
[Java] Convert character strings to uppercase / lowercase (AOJ⑨-swap uppercase and lowercase)
Excel sheet and set Tab colors to rename Java
Java memory management and how to read GC Viewer
[Java] Refer to and set private variables with reflection
Java classes and instances to understand in the figure
I want to transition screens with kotlin and java!
How to convert A to a and a to A using AND and OR in Java
[Java] [XML signature] Add prefix and ID to Signature tag
[Java] Convert JSON to Java and Java to JSON-How to use GSON and Jackson-
Gzip-compress byte array in Java and output to file
Notes on how to use regular expressions in Java