Here is how this is done with a text file. Still working on making it happen with a binary file.
function setDateTimeToUtc() {
var deducedDate = qie.deduceDate(qie.getSystemDate());
var date = new java.util.Date(deducedDate.getTime());
var utc_format = new java.text.SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
utc_format.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
return utc_format.format(date);
}
function getHMAC256(key, valueToEncode) {
var sha256_HMAC = null;
var hash = null;
try {
sha256_HMAC = javax.crypto.Mac.getInstance("HmacSHA256");
var theValue = new java.lang.String(valueToEncode);
var secret_key = new javax.crypto.spec.SecretKeySpec(qie.base64DecodeToBytes(key), "HmacSHA256");
sha256_HMAC.init(secret_key);
hash = qie.base64EncodeBytes(sha256_HMAC.doFinal(theValue.getBytes("UTF-8")));
} catch (e1) {
throw e1;
}
return hash;
}
var blobName = qie.getFileName() + "." + qie.getUUID(true) + ".txt";
var container = <your blob container>;
var accountName = <your blob account>;
var requestMethod = "PUT";
var urlPath = container + "/" + blobName;
var storageServiceVersion = "2015-12-11";
var theDate = setDateTimeToUtc() + " GMT";
var content = source.toString();
var blobType = "BlockBlob";
var canonicalizedResource = "/" + accountName + "/" + urlPath;
var canonicalizedHeaders = "x-ms-blob-type:" + blobType + "\nx-ms-date:" + theDate + "\nx-ms-version:" + storageServiceVersion + "\n";
var accountKey = <your secret key>;
var tokenParameterMap = qie.newParameterMap();
tokenParameterMap.put("http.header.x-ms-version", storageServiceVersion);
tokenParameterMap.put("http.header.x-ms-date", theDate);
tokenParameterMap.put("http.header.x-ms-blob-type", blobType);
var stringToSign = requestMethod + "\n" +
"\n" + //Content Encoding
"\n" + //Content Language
StringUtils.length(content) + "\n" + //Content Length
"\n" + //Content MD5
"text/plain; charset=UTF-8" + "\n" + //Content Type
"\n" + //Date
"\n" + //If - Modified - Since
"\n" + //If - Match
"\n" + //If - None - Match
"\n" + //If - Unmodified - Since
"\n" + //Range +
canonicalizedHeaders + canonicalizedResource;
qie.info(stringToSign);
var theToken = getHMAC256(accountKey, stringToSign);
tokenParameterMap.put("http.header.Authorization", "SharedKey " + accountName + ":" + theToken);
var urlTemplate = "https://" + accountName + ".blob.core.windows.net/" + urlPath;
var tokenWSCall = qie.callRESTWebService(
"CompScorecardBlobStorage",
urlTemplate,
"PUT",
content,
"text/plain",
tokenParameterMap,
60000);
qie.info(tokenWSCall);