amazon glacier File Uploader - Java AWS

Java examples for AWS:Glacier

Description

amazon glacier File Uploader

Demo Code


import java.io.File;
import java.io.IOException;
import java.util.Date;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.glacier.AmazonGlacierClient;
import com.amazonaws.services.glacier.transfer.ArchiveTransferManager;
import com.amazonaws.services.glacier.transfer.UploadResult;


public class FileUploader {
    public static String vaultName = "GLACIER_TEST";

    public static void main(String[] args) throws IOException {
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration.setProxyHost("xx.xx.xx.xx");
        clientConfiguration.setProxyPort(0);

        AWSCredentials credentials = new PropertiesCredentials(
                VaultCreator.class
                        .getResourceAsStream("AwsCredentials.properties"));
        AmazonGlacierClient client = new AmazonGlacierClient(credentials,
                clientConfiguration);/* w  ww.  j a v  a 2 s . c  o  m*/
        client.setEndpoint("https://glacier.ap-northeast-1.amazonaws.com/");
        try {
            File uploadFile = new File("path to upload file");
            ArchiveTransferManager atm = new ArchiveTransferManager(client,
                    credentials);
            long startTime = System.currentTimeMillis();
            UploadResult result = atm.upload(vaultName,
                    "Archive upload test :upload time = " + (new Date()),
                    uploadFile);
            long endTime = System.currentTimeMillis();
            System.out.println("Archive ID: " + result.getArchiveId());
            System.out.println("Upload Time:" + (endTime - startTime)
                    + " msec");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials