Skip to content

Instantly share code, notes, and snippets.

@matoken
Created October 12, 2012 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matoken/3877342 to your computer and use it in GitHub Desktop.
Save matoken/3877342 to your computer and use it in GitHub Desktop.
Amazon Glacier Upload. 引数にUp先のendpoint, Vault とUp したいファイル名を指定する.ファイル名と,archiveID を返す.
import java.io.File;
import java.io.IOException;
import java.util.Date;
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 ArchiveUploadHighLevel {
public static AmazonGlacierClient client;
public static void main(String[] args) throws IOException {
// ENDPOINT
// virginia https://glacier.us-east-1.amazonaws.com/
// oregon https://glacier.us-west-2.amazonaws.com/
// california https://glacier.us-west-1.amazonaws.com/
// ireland https://glacier.eu-west-1.amazonaws.com/
// tokyo https://glacier.ap-northeast-1.amazonaws.com/
String endpoint = args[0];
String vault = args[1];
String archive = args[2];
AWSCredentials credentials = new PropertiesCredentials(
ArchiveUploadHighLevel.class.getResourceAsStream("AwsCredentials.properties"));
client = new AmazonGlacierClient(credentials);
client.setEndpoint(endpoint);
try {
ArchiveTransferManager atm = new ArchiveTransferManager(client, credentials);
UploadResult result = atm.upload(vault, "my archive " + (new Date()), new File(archive));
System.out.println(endpoint + "," + vault + "," + archive + "," + result.getArchiveId());
} catch (Exception e)
{
System.err.println(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment