When I upload a file to the emulator’s storage, onUploadFile is not called. I have no idea what the cause is.version “express”: “^4.18.2″,”firebase-admin”: “^11.8.0″,”firebase-functions”: “^4.6.0”.
There are no errors in the emulator, and the storage is still there.
export const onUploadFile = functions.storage .object()
.onFinalize(async (object) => {
console.log(object);
console.log(“test”); });
This did not work.
import { useState, ChangeEvent } from 'react';
import { ref, uploadBytes } from 'firebase/storage';
import { storage } from '../firebaseConfig';
export const Upload = () => {
const [file, setFile] = useState<File | null>(null);
const handleFileChange = (event: ChangeEvent<HTMLInputElement>) => {
const files = event.target.files;
if (files) {
setFile(files[0]);
}
};
const handleUpload = async () => {
if (file) {
const storageRef = ref(storage, `/${file.name}`);
console.log(storageRef, 'storageRef');
try {
const snapshot = await uploadBytes(storageRef, file);
console.log(
snapshot.metadata.fullPath
);
}
}
};
return (
<div>
<input type="file" onChange={handleFileChange} />
<button onClick={handleUpload}>upload</button>
</div>
);
};
import * as functions from "firebase-functions";
import app from "./server/server";
// eslint-disable-next-line object-curly-spacing
import { onObjectFinalized } from "firebase-functions/v2/storage";
export const api = functions
.runWith({
timeoutSeconds: 500,
})
.https.onRequest(app);
export const onUploadFile = onObjectFinalized(async (object) => {
console.log(object, "test");
});
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix "$RESOURCE_DIR" run lint",
"npm --prefix "$RESOURCE_DIR" run build"
]
}
],
"hosting": {
"public": "frontend/build",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "/api/**",
"function": "api"
},
{
"source": "**",
"destination": "/index.html"
}
]
},
"storage": {
"rules": "storage.rules"
},
"emulators": {
"functions": {
"port": 5001
},
"hosting": {
"port": 5002
},
"auth": {
"port": 9099
},
"storage": { "port": 9199 }
}
}