/* { "expiration": "2007-12-01T12:00:00.000Z", "conditions": [ {"bucket": "johnsmith"}, ["starts-with", "$key", "user/eric/"], {"acl": "public-read"}, {"success_action_redirect": "http://johnsmith.s3.amazonaws.com/successful_upload.html"}, ["starts-with", "$Content-Type", "image/"], {"x-amz-meta-uuid": "14365123651274"}, ["starts-with", "$x-amz-meta-tag", ""] ] } key = '1234' signature = 'abcdef' return Base64.encode64(OpenSSL::HMAC.digest('sha1', key, signature))
*/ BoundS3Image = BoundControl.extend({ //el: false, //model: false, //attribute: false, //binder: false, width: 100, style: 'medium', authenticity_token: false, init: function(params) { for (var thing in params) this[thing] = params[thing]; this.el = this.el ? this.el : this.model.name.toLowerCase() + '_' + this.model.id + '_' + this.attribute.name; if (!this.attribute.update_url) this.attribute.update_url = this.model.update_url; var this2 = this; $('#'+this.el).wrap($('') .attr('id', this.el + '_container') .addClass('mb_container') .css('position', 'relative') ); $('#'+this.el+'_container').empty(); $('#'+this.el+'_container').append($('Uploading...
"); $('#'+this2.el+'_iframe').on('load', function() { $.ajax({ url: this2.attribute.update_url, type: 'post', success: function(resp) { this2.post_upload(); } }); }); return true; }) .append($('').attr('type','hidden').attr('name', "AWSAccessKeyId" ).val(s3.access_key_id)) .append($('').attr('type','hidden').attr('name', "acl" ).val(s3.acl)) .append($('').attr('type','hidden').attr('name', "policy" ).val(s3.policy)) .append($('').attr('type','hidden').attr('name', "Signature" ).val(s3.signature)) .append($('').attr('type','hidden').attr('name', "success_action_status" ).val("200")) .append($('').attr('type','hidden').attr('name', "key" ).val(s3.key)) .append($('') .attr('id', this.el + '_fake_file_input') .addClass('mb_fake_file_input') .append($('') .attr('type', 'button') .attr('id', this.el + '_update_button') .val('Update ' + this.attribute.nice_name) .click(function() { $('#'+this2.el+'_file').click(); }) ) .append($('') .attr('type', 'file') .attr('id', this.el + '_file') .attr('name', 'file') .change(function() { $('#'+this2.el+'_form').trigger('submit'); }) ) .append($('') .attr('type', 'submit') .val('Submit') ) ) ); $('#'+this.el+'_container').append($('') .attr('id', this.el + '_message') ); iframe = $(""); if (this.attribute.debug) iframe.css('width', '100%').css('height', 600).css('background', '#fff'); else iframe.css('width', 0).css('height', 0).css('border', 0); $('#'+this.el+'_container').append(iframe); $('#'+this.el+'_container').append($('" + str + "
"); $('#'+this.el+'_message').slideDown(); var this2 = this; setTimeout(function() { $('#'+this2.el+'_message').slideUp(function() { $(this).empty(); }); }, 3000); } });