MCPcopy Create free account
hub / github.com/firebase/quickstart-js / handleFileSelect

Function handleFileSelect

storage/main.ts:28–54  ·  view source on GitHub ↗
(e: Event)

Source from the content-addressed store, hash-verified

26const storageRef = ref(storage);
27
28function handleFileSelect(e: Event) {
29 e.stopPropagation();
30 e.preventDefault();
31
32 const target = e.target as HTMLInputElement | null;
33 const files = target?.files;
34 if (!target || !files) {
35 return;
36 }
37
38 const file = files[0];
39
40 // Push to child path.
41 uploadBytes(ref(storageRef, 'images/' + file.name), file)
42 .then(function (snapshot) {
43 console.log('Uploaded', snapshot.metadata.size, 'bytes.');
44 console.log('File metadata:', snapshot.metadata);
45 // Let's get a download URL for the file.
46 getDownloadURL(snapshot.ref).then(function (url) {
47 console.log('File available at', url);
48 linkBox.innerHTML = '<a href="' + url + '">Click For File</a>';
49 });
50 })
51 .catch(function (error) {
52 console.error('Upload failed:', error);
53 });
54}
55
56fileInput.addEventListener('change', handleFileSelect, false);
57fileInput.disabled = true;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected