我们正在使用 PLupload 将图像上传到亚马逊 S3 存储桶。但是我们需要为上传的文件设置缓存控制。
我尝试添加标题 {'cache-control':'155520000'},并将其添加到 multipart_params 下。没运气。
以下是我们使用的代码。任何帮助将不胜感激。
$(function() {
$('#progressbar').hide();
var uploader = new plupload.Uploader({
init : {
FilesAdded: function(up, files) {
plupload.each(files, function(file) {
if (up.files.length > 1) {
up.removeFile(file);
}
});
},
},
preinit : {
UploadFile: function(up, file) {
var filenamevous;
if('thumb' in file){
up.settings.multipart_params.key = 'thumb_'+imagename;
}
else
{
up.settings.multipart_params.key = makeid()+'.jpg';
}
imagename = up.settings.multipart_params.key;
var filenamevous;
filenamevous = $("#txtImageTitle").val();
var category;
category = $("#category").val();
$.post("<?php echo $this->config->item('actionFeUrl'); ?>/pictures/ajax",{imname:imagename,oriname:filenamevous,catName:category,task:'uploadedimage'},function(data)
{
});
}
},
runtimes : 'flash,silverlight,html5',
browse_button : 'pickfiles',
container : 'container',
max_file_size : '10mb',
multi_selection: false,
multipart: true,
multipart_params: {
'key': '${filename}',
'Filename': '${filename}',
'acl': 'public-read',
'success_action_status': '201',
'AWSAccessKeyId' : '<?php echo $accessKeyId; ?>',
'policy': '<?php echo $policy; ?>',
'signature': '<?php echo $signature; ?>'
},
url : 'http://<?php echo $bucket; ?>.s3.amazonaws.com/',
flash_swf_url : '<?php echo $this->config->item('base_url'); ?>/plupload/js/plupload.flash.swf',
silverlight_xap_url : '<?php echo $this->config->item('base_url'); ?>/plupload/js/plupload.silverlight.xap',
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
],
});
$('#uploadfiles').click(function(e) {
var pattern = '<?php echo $blackListedWordsPattern; ?>';
var patt=new RegExp(pattern,"gi");
var value = $('#txtImageTitle').val();
if(value==""){
showAlertPopUp('Please enter title.');
return false;
}
if(patt.test(value)) //value is the value from the input feild
{
showAlertPopUp('Name contains a black listed words.');
return false;
}
if($("#category").val()==""){
showAlertPopUp('Please select category.');
return false;
}
$('#uploadfiles').hide();
$('#progressbar').show();
uploader.start();
e.preventDefault();
});
uploader.init();
uploader.splice();
uploader.bind('BeforeUpload', function(up, file) {
if('thumb' in file){
up.settings.resize = {width : 190, height : 143, quality : 100};
}
else{
up.settings.resize = {width : 700, height : 450, quality : 100};
}
});
uploader.bind('FilesAdded', function(up, files) {
$.each(files, function(i, file) {
$('#filelist').html(
'<div style="float:right" id="' + file.id + '">' +
file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +
'</div>');
});
up.refresh(); // Reposition Flash/Silverlight
});
uploader.bind('FileUploaded', function(up, file) {
$('#' + file.id + " b").html("100%");
if(!('thumb' in file)) {
file.thumb = true;
file.loaded = 0;
file.percent = 0;
file.status = plupload.QUEUED;
up.trigger("QueueChanged");
up.refresh();
}
});
uploader.bind('Error', function(up, err) {
$('#filelist').append("<div>Error: " + err.code +
", Message: " + err.message +
(err.file ? ", File: " + err.file.name : "") +
"</div>"
);
up.refresh(); // Reposition Flash/Silverlight
});
});