I am not able to understand why firebase is not accepting the image, the following message is appearing: TypeError: Cannot read property 'byteLength' of undefined
I tried to add the 'byteLength' value to my object(req.file) but the same error continued.
Just below is my implementation
const firebase2 = require('firebase/app');
require('firebase/storage');
router.put('/addimage', multer.single('picture'), async (req, res, next) => {
const newName = uuidv1() + "-" + req.file.originalname;
var storageRef = firebase2.storage().ref('photo/'+ newName);
storageRef.put(req.file);
});
This html example I did work. I am wanting to make a backend so I am migrating to nodejs
<html>
<head>
<meta charset="utf-8">
<title>Teste</title>
<style>
body {
display: flex;
min-height: 100vh;
width: 100%;
padding: 0;
margin: 0;
align-items: center;
justify-content: center;
flex-direction: column;
}
#uploader {
-webkit-appearance: none;
appearance: none;
width: 50%;
margin-bottom: 10%;
}
</style>
</head>
<body>
<progress value="0" max="100" id="uploader">0%</progress>
<input type="file" value="upload" id="fileButton"></input>
<script src="https://gstatic.com/firebasejs/live/3.0/firebase.js"></script>
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "xxxxx",
authDomain: "xxxxx",
projectId: "xxxxx",
storageBucket: "xxxxxxx",
messagingSenderId: "xxxxxx",
appId: "xxxxxxx",
measurementId: "xxxxxx"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
var uploader = document.getElementById('uploader');
var fileButton = document.getElementById('fileButton');
fileButton.addEventListener('change', function(e){
var file = e.target.files[0];
var storageRef = firebase.storage().ref('sweet_fifs/'+ file.name);
var task = storageRef.put(file);
task.on('state_changed',
function progress(snapshot) {
var percetage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
uploader.value = percetage;
},
function error(err) {
}
)
});
</script>
</body>
