I’ve deployed a basic social app and i can fetch all the data submitted by users except images, because they do not get stored, hence I receive a Failed to load resource: the server responded with a status of 404 () cannot find myappname.onrender.com/assets/img1.jpg
I installed multer gridfs and set it up but it still doesn’t work:
app.use(bodyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());
app.use(express.static('public'));
app.use('/assets', express.static('assets'));
/* FILE STORAGE */
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "public/assets");
},
filename: function (req, file, cb) {
cb(null, file.originalname);
},
});
const upload = multer({ storage });
/* ROUTES WITH FILES */
app.post("/auth/register", upload.single("picture"), register);
app.post("/posts", verifyToken, upload.single("picture"), createPost);
/* ROUTES */
app.use("/auth", authRoutes);
app.use("/users", userRoutes);
app.use("/posts", postRoutes);