@שרה-רחל זה נורא פשוט, וכתבתם שזה מגיע מinput file אז הנה דוגמה שכתב GPT
<!DOCTYPE html>
<html lang="he">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>המרת תמונה ל-Base64</title>
</head>
<body>
<h1>המרת תמונה ל-Base64</h1>
<input type="file" id="imageInput" accept="image/*">
<br><br>
<textarea id="base64Output" rows="10" cols="50" placeholder="כאן יופיע קוד Base64"></textarea>
<script>
document.getElementById('imageInput').addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function() {
const base64String = reader.result.split(',')[1];
document.getElementById('base64Output').textContent = base64String;
document.getElementById('base64Output').textContent = reader.result;
};
reader.readAsDataURL(file);
}
});
</script>
</body>
</html>
שימו לב לכפילות
document.getElementById('base64Output').textContent = base64String;
document.getElementById('base64Output').textContent = reader.result;
פשוט הGPT החליט שלא צריך את הכותרת data:image/png;base64, ואני חושב שבמקרה הזה כן צריך