I have a script working in JSFiddle, but it throws an error in WeWeb.
<body>
<!-- Insert this script at the bottom of the HTML, but before you use any Firebase services -->
<script type="module">
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-app.js'
// Add Firebase products that you want to use
import { getStorage, ref, uploadBytesResumable, getDownloadURL } from 'https://www.gstatic.com/firebasejs/10.12.0/firebase-storage.js';
// TODO: Replace the following with your app's Firebase project configuration
const firebaseConfig = {apiKey: "XXXXXX",
authDomain: "harold-staging-v2.firebaseapp.com",
projectId: "harold-staging-v2",
storageBucket: "harold-staging-v2.appspot.com",
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const storage = getStorage();
// Create the file metadata
/** @type {any} */
const metadata = {
contentType: 'image/jpeg'
};
const base64String = 'iVBORw0KGgoAAAANSUhEUgAAADIAAAA0CAMAAAD/uJueAAAAV1BMVEUAAAAQEBDu7u68vLwJCQn6+vobGxv39/f8/Pz4+PhmZmazs7POzs4pKSnn5+ehoaHDw8NycnJAQECHh4eUlJQ2NjZYWFj09PTh4eHX19eqqqpLS0t7e3vPBgSsAAACXUlEQVRIx6WWfRttIAzAlwzzUjgiju//OW/hUOFenrt/PFq/ttpWg/S1wPohRKS/zXMmrAiJrpH6HiLUsukEOcjQAEDVRTcMDVKZCfmqXxDkzIxA3I94RaDO40Vf4I6QNWJF1RcMlu2mznfHKFLbGFTFyTfk1a7V9EPG5DcIScg4BLASNwR5DA7j+Yb1QWybWZAJHEm4w1BZubpuRzp3GKoabeBs7HBUnupzg4Aqx7owUpfl19fMO/LxFZAkLDbCkgSeIrfS/A/SPUXm98hxYvI9Mj1FusuE+atMO1KyZ0TMd6R+iuxpOeRP99LbUoYXRjYz1spjI8bMYBG3Jv8pialLeBHILTLGyuFXkjfVeVY797HrGVDUOlcFlurkvsDhSPVKEJDet5KbE8zkhfcklPMLTugl2vshOAxlQ3E4H9cGOaJiM+h0fm1k86NxIuMitoCwCFI0Gclcp98bpCqzTHzDgM8p4sSczAR0PFFy6jdNLmWzzmNN8TmmMLMXEhehMDvIsrT/rez7CenwvUCUJmcD3loGyS6vpK/Q/eW1RDbHwkgwtjiwxCth57o0yT8Ey/U8V61Mh65VDW8D4xGtJeabYZ9RLCGPRNn4UWK/EktP1/i8vtNzWEnNsL+VYV0ujyLp6pTUtL/IImBim244BbnTa3K6i+jDgm0iBnFhs9ddGOFfb82c177lthi8HsbmdyRbF4q9n1YKDDqlpbWJeKMurjRW5YVwWiLw+iESdZe3FVstmMeyavOO69TroSBsPzCNdMknKeVU1KOO6NSowUUrtb36mCHRfdf3Rv4AT8EqV9CZODMAAAAASUVORK5CYII=';
// Upload file and metadata to the object 'images/mountains.jpg'
const storageRef = ref(storage, 'images/testing.jpg'); // Provide a filename here
const uploadTask = uploadBytesResumable(storageRef, base64String, metadata);
// Listen for state changes, errors, and completion of the upload.
uploadTask.on('state_changed',
(snapshot) => {
// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log('Upload is ' + progress + '% done');
switch (snapshot.state) {
case 'paused':
console.log('Upload is paused');
break;
case 'running':
console.log('Upload is running');
break;
}
},
(error) => {
// A full list of error codes is available at
// https://firebase.google.com/docs/storage/web/handle-errors
switch (error.code) {
case 'storage/unauthorized':
// User doesn't have permission to access the object
break;
case 'storage/canceled':
// User canceled the upload
break;
// ...
case 'storage/unknown':
// Unknown error occurred, inspect error.serverResponse
break;
}
},
() => {
// Upload completed successfully, now we can get the download URL
getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => {
console.log('File available at', downloadURL);
});
}
);
</script>
</body>
What do I change to make it work in WeWeb?
It says Unexpected token ‘<’
And if I remove the body and script tags, it say Cannot use import statement outside a module