是否可以使用jquery / js调整大小或降低分辨率以减小文件的大小?在我的HTML中,我有表格上传多个这样的图像:
<div class="form-group col-sm-12">
<label for="file">Upload Foto</label>
<input name="file[]" id="file" class="btn btn-primary" type="file" multiple >
</div>
<button class="btn btn-primary" type="submit" id="upload">Upload</button>
我想使用ajax创建图像大小上传。这是jquery代码。
$(document).on('submit', '#upload', function () {
var inputFile = $('input#file');
var filesToUpload = inputFile[0].files;
if (filesToUpload.length > 0) {
// provide the form data that would be sent to sever through ajax
var formData = new FormData();
for (var i = 0; i < filesToUpload.length; i++) {
// Do something to resize image or reduce resolution for minimize delay upload
var file = filesToUpload[i];
formData.append("file[]", file, file.name);
}
$.ajax({
url: "<?php echo base_url('surveyor/c_surveyor/add_file_image/'); ?>/" + NO_TANK + EIR_REF,
type: 'post',
data: formData,
processData: false,
contentType: false,
success: function () {
$(":file").val('');
$(":text").val('');
$("#tableClean").find("tr:gt(0)").remove();
$("#tableReport").find("tr:gt(0)").remove();
$('#pilih_isotank').after('<div class="callout callout-success lead" id="div_error"><p id="pesan_error">Semua Data Berhasil Terupload</p></div>');
$('#div_error').fadeIn("fast");
$('#pesan_error').html(obj.Message);
$('#div_error').fadeOut(7000);
}
});
答案 0 :(得分:0)
jQuery不可能。也许使用canvas作为 adeneo 提到,但这是很多工作。不要这样做。