File name for uploaded file
I am using Valum file uploader library. It works fine for me but I need to provide file name with other parameters. For now I am doing the following:
var uploader = new qq.FileUploader({
element: button,
allowedExtensions: ['jpg', 'jpeg', 'png'],
sizeLimit: 2147483647, // max size
action: '/ControllerNAme/Action',
multiple: false,
params: {PostData: Ge开发者_运维知识库tFileUploadData()},
onComplete: function(id, fileName, responseJSON){
//My reload logic here.
},
});
function GetFileUploadData() {
var lFileUploadData = new Object();
//File note is the id of input with type text, in which I type some notes to file
lFileUploadData.FileNote = $('#FileNote').val();
return JSON.stringify(lFileUploadData);
};
But all the time I have this field empty.
You should use onchange
event to get file name, maybe, GetFileUploadData()
function gets the filename on time the file input have not yet been browser to file.
I guess when the following statement initialize at the beginning (means: onload)
var uploader = new qq.FileUploader({
element: button,
allowedExtensions: ['jpg', 'jpeg', 'png'],
sizeLimit: 2147483647, // max size
action: '/ControllerNAme/Action',
multiple: false,
params: {PostData: GetFileUploadData()},
onComplete: function(id, fileName, responseJSON){
//My reload logic here.
},
});
then:
$('#FileNote').val()
is empty when you call GetFifleUploadData()
So, can you try this one:
$("#FileNote").change(function(){
uploader._options.params.PostData = $(this).val();
});
The uploaded file is specified by the fileName
parameter of the onComplete
function, called when the upload is done.
You can then pass this value to the server (if needed).
The params:
section is for parameters sent as POST params, sent to the upload hander URL (specified in action:
section)
精彩评论