μ½”λ”© λ©”λͺ¨

[error] Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.

Dong _ hwa 2023. 5. 20. 21:31

input 을 톡해 이미지λ₯Ό μ—…λ‘œλ“œλ₯Ό ν•˜λŠ” κ³Όμ •μ—μ„œ, λ°œμƒ λ˜λŠ” 였λ₯˜μ΄λ‹€
이미지λ₯Ό μ •μƒμ μœΌλ‘œ μ—…λ‘œλ“œ ν•œλ‹€λ©΄ λ¬Έμ œκ°€ μ—†μœΌλ‚˜, 이미지λ₯Ό μ„ νƒν•˜λŠ” μ°½ κΉŒμ§€ λ„μš΄ μƒνƒœμ—μ„œ μ·¨μ†Œλ₯Ό ν•˜κ²Œ λ˜λŠ” 경우
이미지 파일 μ—…λ‘œλ“œ input에 κ±Έλ € μžˆλŠ” ν•¨μˆ˜λŠ” κ·ΈλŒ€λ‘œ μž‘λ™μ„ ν•˜κ²Œ λ˜λ‚˜, μ‹€μ œ 파일이 μ—†μ–΄μ„œ μ—λŸ¬κ°€ λ°œμƒν•˜κ²Œ λœλ‹€.
확인을 μœ„ν•΄ e.target.file μ„ 체크 ν•΄λ³΄λ‹ˆ, νŒŒμΌμ˜ μ—…λ‘œλ“œ μ‹œ e.target.file의 lengthκ°€ 1 μ—…λ‘œλ“œλ₯Ό μ·¨μ†Œ ν•œ 경우 0이 λ‚˜μ˜€κ²Œ λœλ‹€.

κΈ°μ‘΄ μ½”λ“œ

reader.readAsDataURL(file);

에 쑰건문을 λ‹¬μ•„μ£Όμ—ˆλ‹€

 

λ³€κ²½ μ½”λ“œ

    if (file) {
      reader.readAsDataURL(file);
    }