Problem with upload images in Heroku
See original GitHub issueBug report
I’m having trouble uploading images using Cloudinary Adapter in Production (Heroku)
To Reproduce
Steps to reproduce the behaviour. Please provide code snippets or a repository:
- Set
secureCookies: false
- Set
app.set("trust proxy", 1);
- Deploy to Heroku
- Try upload image
- In console show this error
[Network error]: ServerParseError: JSON.parse: unexpected character at line 1 column 1 of the JSON data TypeError: e is undefined
In remote console
2020-01-17T14:03:17.474496+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/admin/api" host=jumpittlabs-site-cms.herokuapp.com request_id=14e94647-88b8-43ef-9329-1aa1de849451 fwd="152.231.93.178" dyno=web.1 connect=1ms service=345ms status=503 bytes=0 protocol=https
Expected behaviour
I want upload image as it does in development
System information
- OS: Heroku?
- Firefox, Safari and Chrome
Screenshot
https://i.imgur.com/AyKyP7z.png
Aditional information
This is my index.js
require("dotenv").config();
const { Keystone } = require("@keystonejs/keystone");
const { PasswordAuthStrategy } = require("@keystonejs/auth-password");
const { GraphQLApp } = require("@keystonejs/app-graphql");
const { AdminUIApp } = require("@keystonejs/app-admin-ui");
const { MongooseAdapter: Adapter } = require("@keystonejs/adapter-mongoose");
const expressSession = require('express-session');
const MongoStoreMaker = require("connect-mongo");
const User = require("./models/User");
const Member = require("./models/Member");
const Project = require("./models/Project");
const Department = require("./models/Department");
const bodyParser = require("body-parser");
const { makeANiceEmail, transport } = require("./src/mail");
const MongoStore = MongoStoreMaker(expressSession);
const { ExpressApp } = require("@keystonejs-contrib/app-express");
const keystone = new Keystone({
name: "jumpittlabs-site-cms",
adapter: new Adapter(),
sessionStore: new MongoStore({
url: process.env.DATABASE_URL
}),
secureCookies: false
});
keystone.createList("User", User);
keystone.createList("Member", Member);
keystone.createList("Project", Project);
keystone.createList("Department", Department);
const authStrategy = keystone.createAuthStrategy({
type: PasswordAuthStrategy,
list: "User"
});
module.exports = {
keystone,
apps: [
new GraphQLApp(),
new AdminUIApp({ authStrategy }),
new ExpressApp(app => {
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.post("/email", async function (req, res) {
await transport.sendMail({
from: "'Mr. Fox 🦊' <user@website.com>",
to: "alvaaz_@hotmail.com",
subject: "Hello World",
text: "Hello World?",
html: makeANiceEmail
}, (error, info) => {
if (error) {
return console.log(error);
}
console.log("Message sent: %s", info.messageId);
res.sendStatus(200);
});
});
})
],
configureExpress: app => {
if (process.env.NODE_ENV !== "development") {
app.set("trust proxy", 1);
}
}
};
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Image upload functionality not working on deployed Heroku ...
Heroku is not suitable for persistent storage of data, the uploaded pictures would be deleted after a while (when the dyno is restarted) ......
Read more >Why photo not upload when i deploy on heroku
I made a MERN project,there for my backend i use multer for form upload. It work perfectly in my local machine and posted...
Read more >Why are my file uploads missing/deleted from the Application
Issue. Files are uploaded to the app but then disappear or are deleted after a while. Resolution. The Heroku filesystem is ephemeral -...
Read more >Problem with upload images in Heroku · Issue #2256 - GitHub
Bug report I'm having trouble uploading images using Cloudinary Adapter in Production (Heroku) To Reproduce Steps to reproduce the behaviour.
Read more >image upload works locally, but the deployed version ... - Reddit
So it's it's not logging any error in the console. Images are uploaded on AWS. It works locally but not on heroku ....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This fixed a similar issue for me. The error in the logs was the following: EDIT: (This only happened while uploading images)
fixed by updating the engines on the package.json
thanks @alvaaz
Yep. I fix it for now, setting node version to 12.13.x in Heroku.