我正在将文件发送到s3存储桶,然后再发送需要验证的文件是否为pdf,如果pdf需要将内容类型设置为application / pdf有人可以建议我是javascript新手吗
add: function(e, data) {
$('#upload-container').append('<div>* ' + data.files[0].name + '</div>');
$('#upload-files').on('click', function(e){
e.preventDefault();
fileExtension = data.files[0].name.substr((data.files[0].name.lastIndexOf('.') + 1));
console.log (fileExtension);
if (fileExtension == "pdf"){
data.submit();
console.log(data.files[0]);
}
else{
alert("Please Upload Pdf file")
}
})
},
submit: function(e, data) {
var fileName = data.files[0].name;
content = data.files[0].type;
console.log(content);
if ($.inArray(fileName, fileNames) === -1){ fileNames.push(fileName); }
else { return false; }
},
这是我正在发送的ajax请求
done: function (e, data) {
var params = {
file_name: data.files[0].name,
debt_id: $('#debt-id')[0].value,
category: $("select[name='document_category']")[0].value
}
$.ajax({
type: 'POST',
url: '/documents/create',
data: params,
error: function(response){
console.log('Something went weird, document not created.')
console.log(response)
},
success: function(response){
$('#upload-container').html('');
$('#progress .bar').css( 'width', '0%');
response = JSON.parse(response);
$('#debts_documents_list').prepend(
'<span class="date">' + response.document_date + '</span>' +
'<span class="title">' + response.document_title + '</span>' +
'<span class="type">' + response.document_category + '</span>' +
'<span class="download"><a href=' + response.document_url + ' target="_blank" class="btn_small">Download</a></span>'
);
/*
* closing the modal
*/
$( ".pf4_modal" ).removeClass('active');
$( ".pf4_modal_bg" ).removeClass('active');
$( "body" ).removeClass('pf4_modal_body');
$(".modal_content_action .pf4_modal_upload_close_js").trigger('click');
//console.log('Document created on DB')
//console.log(response)
}
});
},
快速回复应该会很有帮助