У меня есть api, созданный с использованием express. js, он содержит загрузку и отображение изображения, это слово идеально в localhost, а также в локальной сети heroku, но в том же проекте в облаке heroku, все также работают, за исключением того, что изображение не отображается, я не знаю, вставлено ли изображение в папку или нет, потому что я не вижу файлы или папку в heroku .... это мой код для загрузки изображения, и он работает в локальном heroku:
const filter = (req, file, cb)=>{
if(file.mimetype == "image/jpg" || file.mimetype == "image/jpeg" || file.mimetype == "image/png"){
cb(null, true)
}else{
cb(null, false);
}
}
const upload = multer({
filter: filter
});
app.post('/service' ,upload.single('file'), checkAdminAuth, (req, res, next)=>{
try {
req.file != null ?
sharp(req.file.buffer).resize(200, 200).toFile('upload/'
+req.file.originalname,
(err, resizeImage) => {
if (err) {
console.log(err);
} else {
// fs.unlinkSync(req.file.path)
console.log(resizeImage);
}
}) : ""
// fs.unlinkSync(req.file.path)
next()
return res.status(201).json({
message: 'success'
});
} catch (error) {
console.error(error);
}
});
app.use('/upload', express.static('upload'));
/////////////// это лог от heroku:
2020-08-03T12:27:53.175084+00:00 heroku[web.1]: State changed from starting to up
2020-08-03T12:27:54.300490+00:00 app[web.1]: ::ffff:10.69.19.99 - - [03/Aug/2020:12:27:54 +0000] "GET /service/cat/5f27f0f6d3b2d900249dbcb7 HTTP/1.1" 200 329
2020-08-03T12:27:54.301859+00:00 heroku[router]: at=info method=GET path="/service/cat/5f27f0f6d3b2d900249dbcb7" host=infinite-meadow-47540.herokuapp.com request_id=3fd0deaa-3237-4150-8e42-08aa484baebe fwd="185.95.207.81" dyno=web.1 connect=0ms service=32ms status=200 bytes=686 protocol=https
2020-08-03T12:27:55.404054+00:00 app[web.1]: ::ffff:10.155.88.71 - - [03/Aug/2020:12:27:55 +0000] "GET /service/cat/5f27f0f6d3b2d900249dbcb7 HTTP/1.1" 200 329
2020-08-03T12:27:55.404547+00:00 heroku[router]: at=info method=GET path="/service/cat/5f27f0f6d3b2d900249dbcb7" host=infinite-meadow-47540.herokuapp.com request_id=b4c72174-4e32-4013-be61-f39cd3311b53 fwd="185.95.207.81" dyno=web.1 connect=0ms service=6ms status=200 bytes=686 protocol=https
2020-08-03T12:27:56.443405+00:00 app[web.1]: ::ffff:10.45.252.73 - - [03/Aug/2020:12:27:56 +0000] "GET /service/cat/5f27f0f6d3b2d900249dbcb7 HTTP/1.1" 200 329
2020-08-03T12:27:56.446998+00:00 heroku[router]: at=info method=GET path="/service/cat/5f27f0f6d3b2d900249dbcb7" host=infinite-meadow-47540.herokuapp.com request_id=2c77f41c-4bc4-4f52-b8ed-885d0c7e9544 fwd="185.95.207.81" dyno=web.1 connect=0ms service=5ms status=200 bytes=686 protocol=https
2020-08-03T12:27:56.819064+00:00 heroku[router]: at=info method=GET path="/upload/image_picker8301926133547768645.jpg" host=infinite-meadow-47540.herokuapp.com request_id=7d95912d-be4a-42a7-9b65-da69cd26a4b1 fwd="185.95.207.81" dyno=web.1 connect=0ms service=5ms status=404 bytes=573 protocol=https
2020-08-03T12:27:56.822720+00:00 app[web.1]: ::ffff:10.30.127.176 - - [03/Aug/2020:12:27:56 +0000] "GET /upload/image_picker8301926133547768645.jpg HTTP/1.1" 404 181
2020-08-03T12:28:00.626092+00:00 heroku[router]: at=info method=GET path="/cat" host=infinite-meadow-47540.herokuapp.com request_id=e836406a-c878-4cde-a649-05757d0bdc5b fwd="185.95.207.81" dyno=web.1 connect=5ms service=6ms status=200 bytes=848 protocol=https
2020-08-03T12:28:00.627757+00:00 app[web.1]: ::ffff:10.79.206.66 - - [03/Aug/2020:12:28:00 +0000] "GET /cat HTTP/1.1" 200 491
2020-08-03T12:28:00.642170+00:00 app[web.1]: ::ffff:10.9.247.118 - - [03/Aug/2020:12:28:00 +0000] "GET /cat HTTP/1.1" 200 491
2020-08-03T12:28:00.644944+00:00 heroku[router]: at=info method=GET path="/cat" host=infinite-meadow-47540.herokuapp.com request_id=560a35d0-df32-463b-b8c1-eb4823afa3f8 fwd="185.95.207.81" dyno=web.1 connect=0ms service=7ms status=200 bytes=848 protocol=https
2020-08-03T12:28:01.583557+00:00 heroku[router]: at=info method=GET path="/cupload/139585975-e-learning-concept-with-blurred-city-abstract-lights-background.jpg" host=infinite-meadow-47540.herokuapp.com request_id=46562fa8-ac78-4f59-897e-0e44a2b6901e fwd="185.95.207.81" dyno=web.1 connect=0ms service=14ms status=404 bytes=616 protocol=https
2020-08-03T12:28:01.585907+00:00 app[web.1]: ::ffff:10.63.145.147 - - [03/Aug/2020:12:28:01 +0000] "GET /cupload/139585975-e-learning-concept-with-blurred-city-abstract-lights-background.jpg HTTP/1.1" 404 224
2020-08-03T12:28:06.990644+00:00 app[web.1]: ::ffff:10.45.155.176 - - [03/Aug/2020:12:28:06 +0000] "GET /cupload/139585975-e-learning-concept-with-blurred-city-abstract-lights-background.jpg HTTP/1.1" 404 224
2020-08-03T12:28:06.998251+00:00 heroku[router]: at=info method=GET path="/cupload/139585975-e-learning-concept-with-blurred-city-abstract-lights-background.jpg" host=infinite-meadow-47540.herokuapp.com request_id=b9e68097-d78c-4d5e-b9da-08a5a6779bdd fwd="185.95.207.81" dyno=web.1 connect=0ms service=8ms status=404 bytes=616 protocol=https
2020-08-03T12:28:30.181544+00:00 app[web.1]: Error: ENOENT: no such file or directory, open 'upload/b858c17a46a29f9d7ddff5779df988dd'
2020-08-03T12:28:30.186011+00:00 heroku[router]: at=info method=POST path="/service" host=infinite-meadow-47540.herokuapp.com request_id=66638e1f-8082-4624-ad3b-becae5428427 fwd="185.95.207.81" dyno=web.1 connect=1ms service=10241ms status=500 bytes=404 protocol=https
2020-08-03T12:29:21.876414+00:00 app[web.1]: Error: ENOENT: no such file or directory, open 'upload/8e8c7129133e0d2819bd1299d922767b'
2020-08-03T12:29:21.878333+00:00 heroku[router]: at=info method=POST path="/service" host=infinite-meadow-47540.herokuapp.com request_id=2b6a2985-ceb8-4774-8000-4b320ef162f4 fwd="185.95.207.81" dyno=web.1 connect=0ms service=11393ms status=500 bytes=404 protocol=https
2020-08-03T13:01:53.096720+00:00 heroku[web.1]: Idling
2020-08-03T13:01:53.098427+00:00 heroku[web.1]: State changed from up to down
2020-08-03T13:01:54.003136+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-08-03T13:01:54.083729+00:00 heroku[web.1]: Process exited with status 143
2020-08-03T13:43:12.000000+00:00 app[api]: Build started by user osama.cs@cihanuniversity.edu.iq
2020-08-03T13:43:38.449759+00:00 app[api]: Deploy 40ec5723 by user osama.cs@cihanuniversity.edu.iq
2020-08-03T13:43:38.449759+00:00 app[api]: Release v9 created by user osama.cs@cihanuniversity.edu.iq
2020-08-03T13:43:38.613016+00:00 heroku[web.1]: State changed from down to starting
2020-08-03T13:43:41.000000+00:00 app[api]: Build succeeded