It's going to blow up. I've been trying to render the user's picture tonight, but I can't show it
I don't know where the problem is, but today I really understand a lesson, and I still need help from others. Today it's 9 o'clock, so I won't bother the teacher.
Tomorrow we must ask the teacher what's the matter, the code is the same, why can't my picture render???
/**
* Created by Administrator on 2017/6/11.
*/
var express = require('express')
var app = express()
var cors = require('cors')
var bodyParaser = require('body-parser');
var fileUpload = require('express-fileupload');
var path = require('path');
app.use('/static', express.static(path.join(__dirname, 'static'))); //use middleware
app.use(bodyParaser.json()); //with json Form to send data to the back end, using this middleware
var user = require('./apps/user')
const model = require('./config/model');
app.set('json spaces', 4);
app.use(bodyParaser.json());
app.get('/',function (req,res) {
res.send('hello world')
})
app.use(cors());
app.use(fileUpload());
app.use('/user',user)
app.use('/post',require('./apps/post'))
app.use('/comment',require('./apps/comment'))
app.use('/message',require('./apps/message'))
app.post('/upload', function (req, res) { //File upload
var file = req.files.file; //Get the client file file
var name = Date.parse(new Date()) + '.' + file.name; //Print current timestamp + file name
var url = 'http://localhost:3000/static/uploads' + name; //Get file name
var p = path.join(__dirname, 'static', 'uploads', name); //File directory found
file.mv(p, function (err) { //Move temporary files in memory
if (err) //Report errors
return res.status(500).send(err);//Return status code in case of error
res.send({ url: url }); //url Address sent to client
});
})
app.get('/admin', function (req, res) {
res.render('admin');
});
app.listen(3000)
The relevant code of file upload is as above.
I also put files in upload. Why not display them?
It just took another 10 minutes. I tried again, but I still couldn't show
Forget it, I'm a bit stupid. I should ask the teacher to solve it as soon as possible. I've wasted all night
Let's take a lesson.
I didn't write any code today. I spent the whole night correcting this bug. In the end, I still No solution.
Let's not talk about it. Good night, everyone. Count down the 8th day.
Nice Dream.