Я реализовал plupload в своем приложении MVC. Все шло хорошо, но было на виду.
Я решил переместить его в собственный файл:
Он больше не работает, так как не может найти plupload.flash.swf или plupload.silverlight.xap.
Вот содержимое pluploadimplementation.js:
$(function () {
$("#dialog").dialog({
autoOpen: false,
buttons: {
"OK": function () {
var invoiceComment = {
InvoiceId: invoiceId,
Comment: $('#comment').val()
};
$.post('/Invoice/AddComment', invoiceComment);
$(this).dialog('close');
}
}
});
$(".btncomment").click(function () {
invoiceId = $(this).attr("data-invoiceid");
$("#dialog").dialog('open');
});
var filelist = $('#filelist');
var pickfiles = $('#pickfiles');
var uploadfiles = $('#uploadfiles');
var uploader = new plupload.Uploader({
runtimes: 'flash,silverlight,html5,html4',
//runtimes: 'silverlight,html5, html4',
//runtimes: 'html5,html4',
//runtimes: 'html4',
browse_button: pickfiles.attr('id'),
container: 'container',
max_file_size: '10mb',
//chunk_size: '1mb',
multi_selection: false,
multipart: true,
urlstream_upload: true,
url: '@Url.Action("Upload", "Invoice")',
flash_swf_url: '@Url.Content("~/Scripts/plupload/js/plupload.flash.swf")',
silverlight_xap_url: '@Url.Content("~/Scripts/plupload/js/plupload.silverlight.xap")',
filters: [
{ title: "Image Files", extensions: "jpg,gif,png,pdf" },
{ title: "Zip Files", extensions: "zip" },
{ title: "Office Files", extensions: "doc,docx,xls,xlsx" }
],
resize: { width: 320, height: 240, quality: 90 }
});
uploader.bind('Init', function (up, params) {
showpickfiles(true);
});
uploadfiles.click(function (e) {
uploader.start();
e.preventDefault();
});
uploader.init();
uploader.bind('FilesAdded', function (up, files) {
filelist.empty();
$.each(files, function (i, file) {
filelist.append('<div id="' + file.id + '">' + file.name +
' (' + plupload.formatSize(file.size) + ') <b></b>' +
'<a href="#" id="cancel' + file.id + '" class="cancel"> [Cancel]</a>');
//Bind cancel click event
$('#cancel' + file.id).click(function () {
$('#' + file.id).remove();
showpickfiles(true);
uploader.removeFile(file);
uploader.refresh();
});
showpickfiles(false);
});
up.refresh(); // Reposition Flash/Silverlight
})
uploader.bind('UploadProgress', function (up, file) {
$('#' + file.id + " b").html(file.percent + "%");
});
uploader.bind('Error', function (up, err) {
if (err.code == -600) {
filelist.append('<div style="color: #CC0000;">Error - File size is greater than 10MB'
+ (err.file ? ', File: ' + err.file.name : "") + '</div>');
}
else {
filelist.append('<div style="color: #CC0000;">Error - ' + err.message
+ (err.file ? ', File: ' + err.file.name : "") + '</div>');
}
up.refresh(); // Reposition Flash/Silverlight
});
uploader.bind('FileUploaded', function (up, file) {
$('#' + file.id + " b").html("100%");
$('#cancel' + file.id).remove();
pickfiles.html('[Replace Invoice]');
showpickfiles(true);
up.refresh();
});
var showpickfiles = function (show) {
if (show) {
pickfiles.show();
uploadfiles.hide();
} else {
pickfiles.hide();
uploadfiles.show();
}
}
});
Я неправильно указал расположение этих файлов?