最近、メンバーが画像をアップロードする機能を実装しました。数ヶ月間うまくいっています。最近、Chromeでの作業は中止されましたが、Firefox、Safari、Internet Explorerでは引き続き動作します。Chromeのアップロード画像はもう機能しません。他のブラウザは大丈夫です
次のようにクロムが生成されていることをエラーメッセージは次のとおりです。
キャッチされない例外TypeError:「HTMLInputElementの」オン「ファイル」プロパティを設定できませんでした:指定された値がタイプでない「ファイルリスト」。
次のように問題を有するされたコードセクションがある:
$(window).load(function()
{
var aFiletypesAllowed = ["png","gif","jpeg","jpg"];
var FileTypesPrintable = 'png, gif, jpeg, jpg"';
var form = document.getElementById('image-submit');
var options =
{
thumbBox: '.thumbBox',
imgSrc: ''
}
var cropper = $('.imageBox').cropbox(options);
$('#file').on('change', function()
{
var reader = new FileReader();
reader.onload = function(e)
{
options.imgSrc = e.target.result;
cropper = $('.imageBox').cropbox(options);
}
reader.readAsDataURL(this.files[0]);
this.files = [];
fileSize = this.files[0].size;
fileName = this.value;
})
$('#btnCrop').on('click', function()
{
//file validation
var filetype = fileName.split('.').pop().toLowerCase();
fileWidth = cropper.getWidth();
fileHeight = cropper.getHeight();
//check file type
if (aFiletypesAllowed.indexOf(filetype) < 0)
{
var filenameUsed = fileName.split('\\').pop();
jConfirm('Invalid Filetype', filenameUsed + ' is not an allowed file type. Allowed filetypes are ' + FileTypesPrintable, '', '', '', '', '', '', '', '', 180);
document.getElementById('file').value = '';
}
//check image dimensions -- at least one dimension must be over the limit to ensure a crop occurs, and the image is modified in some way
else if (fileWidth < 200 && fileHeight < 200)
{
jConfirm('Image too Small', 'Minimum allowed image size is 200 x 200. Your image is ' + fileWidth + ' x ' + fileHeight + '. Please choose a larger image.', '', '', '', '', '', '', '', '', 180);
document.getElementById('file').value = '';
}
//validation passed, perform crop
else
{
var img = cropper.getDataURL();
$('.cropped').html('<img id="cropped-img" src="'+img+'">'); //image to display
$('#cropped-to-send').val(img); //dataURL to upload
}
})
エラーメッセージは、コードの行によって生成されているように見える「this.files = [];」。このエラーが発生すると、別のエラーが "var filetype = fileName.split( '。')。pop()。toLowerCase();という行でスローされます。その行のエラーは "fileNameが定義されていません"です。
前述のとおり、この機能はChromeで数ヶ月間正常に動作し、Firefox、Safari、Internet Explorerで正常に動作し続けます。
使用しているコードは? – epascarello
タイプ 'FileList'の値はありますか? –
* "最近実装した" *は、エラーをスローするコードはどこにありますか? – charlietfl