-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
36 lines (30 loc) · 1002 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.11.1/firebase-app.js";
import {
getStorage,
ref,
uploadBytes,
getDownloadURL,
} from "https://www.gstatic.com/firebasejs/10.11.1/firebase-storage.js";
import { firebaseConfig } from "./config.js";
const app = initializeApp(firebaseConfig);
const storage = getStorage(app);
const imagePreview = document.getElementById("imagePreview");
async function retiriveImage() {
const storageRef = ref(storage, `images/framephoto`);
const imageURL = await getDownloadURL(storageRef);
imagePreview.src = imageURL;
}
async function uploadImage() {
const fileInput = document.getElementById("fileInput");
const file = fileInput.files[0];
if (file) {
const storageRef = ref(storage, `images/framephoto`);
await uploadBytes(storageRef, file);
}
}
const uploadButton = document.getElementById("uploadButton");
uploadButton.addEventListener("click", () => {
uploadImage();
retiriveImage();
});
retiriveImage();