0
이제 업로드 부분을 완료했습니다. 그냥 사진을 업로드 할 수 있습니다. 사진을 업로드하지 않고 파일을 업로드하면 웹 사이트에 []가 표시되는데 문제가 있습니다. Bascially 난 그냥 업로드를 거부 싶어요. 나는 무슨 일이 일어나고 있는지 잘 모르겠습니다. 그리고 그림에 대한 영구 링크는 어떻게해야합니까? 여기 내 코드입니다 :사진을 업로드하고 해당 사진을 빠른 js에 영구 링크가되게하려면
var express = require('express');
var router = express.Router();
var multer = require('multer');
var upload = multer({
dest: 'public/uploads/', fileFilter: function (req, file, cb) {
if (file.mimetype !== 'image/png'
&& file.mimetype !== 'image/jpg'
&& file.mimetype !== 'image/jpeg'
&& file.mimetype !== 'image/gif') {
console.log('wrong type')
return cb(null, false, new Error('goes wrong on the mimetype'));
}
return cb(null, true);
}
});
/* GET home page. */
router.get('/', function (req, res) {
res.render('index', { title: 'Express' });
});
router.post('/', upload.any(), function (req, res) {
res.send(req.files);
});
module.exports = router;
에서 fileinfo는 'mimetype'입니다. 여기에서는'image/png','image/jpeg' 만 허용 할 수 있습니다 ... – Julian
마침내 당신의 요지가 있고 영구 링크에 대해 알고 있습니까? – OtakuFitness
임의의 문자열이나 uuid를 사용하기 만하면됩니다. 이 문자열이있는 URL에서 이미지에 항상 액세스 할 수있게하려면 suse 만 사용해야합니다. 예 : '/ images/uploads/3b052762054c480181138cf1fd138d3f.png' – Julian