New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ERROR UPLOADING FILE using the javascript and I also use multer in handling the fileupload #1224
Comments
You didn't attach the specific error you got, but as far as I can see:
|
I am having a error too, I dont understand what I am doing wrong Error: const path = require('path'); routes.post('/product-file-upload',upload2.single('product_file'),require('../controllers/products/updateSwagProducts')); The file contents are coming through the request but I somehow cant save it, even though I have created the uploads folder |
Post the |
what are the error of my code ?
"this is the upload photo code
const express = require('express');
const multer = require('multer');
const path = require('path');
const { DB_CURRENT_TIMESTAMP, queryDb } = require('@api/utils/mysql');
//const app = express();
//const port = process.env.SERVER_PORT || 3000;
const router = express.Router();
// Set up storage for uploaded files
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, '../assets/uploads');
},
filename: function (req, file, cb) {
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
const fileExtension = path.extname(file.originalname);
cb(null, file.fieldname + '-' + uniqueSuffix + fileExtension);
}
});
const upload = multer({ storage: storage });
// Serve uploaded files statically
//app.use('/uploads', express.static('uploads'));
router.use('/uploads', express.static('uploads'));
// Handle file upload
router.post('/api/upload-photo', upload.single('image'), async (req, res) => {
if (!req.file) {
return res.status(400).json({ message: 'No file uploaded' });
}
// You can perform additional logic here, like saving the file path to a database
// and returning a response.
res.status(200).json({ message: 'Image Uploaded' });
});
// app.listen(port, () => {
// console.log(
Server is running on port ${port}
);// });
module.exports = router;
and these are the "get gallery data" code
//get all gallery
const { queryDb } = require('@api/utils/mysql');
module.exports = async function(req, res) {
try {
var {
}
The text was updated successfully, but these errors were encountered: