Thanks guys - to be honest it's not really useful if you can't upload files, but figured out uploading eventually.
Here's code I used which may help others. Apologies for not being a stylistically good programmer.
prefunction sizedImage(area, target, name) {
/*
Code: Select all
takes input filename assumed to be in SIRV
adds the SIRV resizing flags as appropriate
downloads & caches the file at the resized-size in local browser HTML5 filesystem
then puts the result cached URL in either an IMG or as Background
stores the original url path in the element as an attribute (linkName)
each image @ each size downloaded once until app removed
fantastic for thumbnails and frequent-use images
NOTE: if you happen to pass an APPERY file object... function fails gracefully
the size flags won't cause problems, but the cached image will be full-size
you will not have the speed of resized and cached small images for refreshes
area = src | url
target = jquery target element
name = url of stored SIRV file
*/
Code: Select all
var width = $(target).width();
var height = $(target).height();
var url = name.split("?")[0]; // clean url
$(target).attr("linkName", url); // store clean url
//callbacks defined
var _success = function(a, b) {
console.log("Cacheing: success"); // returned ok
};
var _failed = function(a, b) {
console.log('Cacheing: failed'); // problem with cache
};
var _cacheImgFile = function(file, path) { // result of request for img cache hit
if (path !== undefined) { // got a cache url (!= original file name at all)
$(target).attr("src", path);
_success();
} else { // no cache hit
$(target).attr("src", file);
ImgCache.cacheFile(file, _success); // save the file
}
};
var _cacheBackgroundFile = function(file, path) { // req or background-image
if (path !== undefined) { // got it
$(target).css("background-image", "url(" + path + ")");
_success();
} else { // no cache hit
$(target).css("background-image", "url(" + file + ")");
ImgCache.cacheFile(file, _success); // save the file
}
};
// variable logic
switch (area) {
case "src":
url = url + "?scale.width=" + width;
if (globalImageCacheOn) {
ImgCache.getCachedFileURL(url, _cacheImgFile, _cacheImgFile);
} else {
$(target).attr("src", url);
}
break;
case "url":
url = url + "?scale.width=" + width;
if (globalImageCacheOn) {
ImgCache.getCachedFileURL(url, _cacheBackgroundFile, _cacheBackgroundFile);
} else {
$(target).css('background-image', 'url(' + url + ')');
}
break;
default:
}
}
/*
Code: Select all
upload file to SIRV system using AWS S3 logic
must preload the amazon javascript somewhere before calling this
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "https://sdk.amazonaws.com/js/aws-sdk-2.1.43.js";
head.appendChild(script);
*/
function uploadSirvFile(file, name, result) {
/*
set up AWS configuration with SIRV account (don't distribute your keys)
set up AWS endpoint for SIRV
point to bucket set up with SIRV account
set up file transfer information (I use my /input area)
Code: Select all
file = file object an type element
name = target file name
result = asynchronous callback
*/
// set up AWS with SIRV account keys
Code: Select all
AWS.config.update({
accessKeyId: '',
secretAccessKey: '',
s3ForcePathStyle: true
});
// dictated by SIRV
Code: Select all
var ep = new AWS.Endpoint('s3.sirv.com');
// MYBUCKET also comes from SIRV
Code: Select all
var bucket = new AWS.S3({
params: {
Bucket: ''
},
endpoint: ep
});
var params = {
Key: "input/" + name,
ContentType: file.type,
Body: file
};
// shoot it to SIRV. Will call result when finished
Code: Select all
bucket.upload(params, result);
}/pre
So there you go.