String description,
PrintStream info,
PrintStream debug)
throws ExecutionProblem
{
S3Service s3Service = null;
boolean rw = true;
try
{
AccessControlList acl = null;
String awsAccessKey = this.args.getXferS3ID();
s3Service = this.getService();
String baseBucketName = this.args.getS3Bucket();
PrintStream pr = null;
if (info != null) {
pr = info;
} else if (debug != null) {
pr = debug;
}
String key = this.makeKey(vmName, null);
File file = new File(localfile);
if (pr != null) {
pr.println("\nTransferring");
pr.println(" - Source: " + file.getName());
String destUrlString = "cumulus://" + baseBucketName + "/" + key;
pr.println(" - Destination: " + destUrlString);
pr.println();
pr.println("Preparing the file for transfer:");
}
CloudProgressPrinter progressWatcher =
new CloudProgressPrinter(pr, file.length(), this.args.getNoSpinner());
S3Object s3Object = ObjectUtils.createObjectForUpload(
key, file, null, false, progressWatcher);
progressWatcher.flush();
s3Object.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM);
if (pr != null) {
pr.println("\n\nTransferring the file:");
}
CumulusInputStream cis = new CumulusInputStream(
file.length(), pr, s3Object.getDataInputStream(), this.args.getNoSpinner());
s3Object.setDataInputStream(cis);
if(this.args.getCommonVMSet())
{
if (pr != null) {
pr.println("Setting permissions for common use.");
}
rw = false;
acl = AccessControlList.REST_CANNED_PUBLIC_READ;
s3Object.setAcl(acl);
}
s3Service.putObject(baseBucketName, s3Object);
progressWatcher.flush();
s3Object.closeDataInputStream();
cis.close();
if(description != null)
{
String descObjName = getDescriptionFileKey(vmName, rw);
S3Object descObj = new S3Object(descObjName, description);
if (acl != null)
{
descObj.setAcl(acl);
}
s3Service.putObject(baseBucketName, descObj);
}
if (pr != null) {
pr.println("");
pr.println("");