Image upload through AdminUI fails with server error: [Network error]: ServerParseError: Unexpected token < in JSON at position 0
See original GitHub issueBug report
Describe the bug
When I go to the AdminUI and click on CREATE in my Image list and then click on UPLOAD FILE and select a file, when I click on CREATE a second time (this time inside the little window that opened on the first ‘create’) to upload the image, the image upload fails.
To Reproduce
- Create an Image list using a
LocalFileAdapter
to upload the image
// index.ts
const staticPath = 'public';
const staticRoute = '';
const imageFileAdapter = new LocalFileAdapter({
src: `${staticPath}/images`,
path: `${staticRoute}/images`
})
// lists/Image.ts
import { File } from '@keystonejs/fields';
import log from '../util/log';
export default (keystone, { imageFileAdapter }) => {
log(`file adapter for image ${imageFileAdapter}`);
keystone.createList('Image', {
schemaDoc: 'Image for Article',
labelResolver: item => item?.file?.originalFilename ?? '',
fields: {
file: { type: File, adapter: imageFileAdapter }
}
});
};
- Add this Image list to Keystone app
- Boot app and go to AdminUI (AdminUI has AuthStrategy enabled)
- Go to Image list. Click on CREATE to create new Image. Select a file to upload and then click on CREATE a second time to upload it.
The following errors are traced to the console
and the network info is
Expected behaviour
The image should upload and be stored on the server and reflected in the AdminUI
Screenshots
System information
- OS: MacOS 10.14
- Browser: Chrome, Firefox (latest)
Additional context
Image upload through the AdminUI worked for the first 6 weeks of our project, stopped working about two weeks ago (for reasons unknown, although the code was the same – change in keystone packages?), started working again last week after an upgrade of all packages, and since a new upgrade in the last two days to the very latest packages has stopped working again, but with different errors.
These are the package versions I have now:
"@keystonejs/adapter-mongoose": "^8.0.1",
"@keystonejs/app-admin-ui": "^5.9.5",
"@keystonejs/app-graphql": "^5.1.5",
"@keystonejs/app-next": "^5.1.2",
"@keystonejs/app-static": "^5.1.2",
"@keystonejs/auth-password": "^5.1.5",
"@keystonejs/field-content": "^5.4.5",
"@keystonejs/fields": "^9.0.0",
"@keystonejs/fields-markdown": "^5.1.5",
"@keystonejs/fields-wysiwyg-tinymce": "^5.2.3",
"@keystonejs/file-adapters": "^6.0.1",
"@keystonejs/keystone": "^8.0.0",
"@keystonejs/list-plugins": "^5.1.4",
"@keystonejs/oembed-adapters": "^5.1.3",
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
@MadeByMike Thanks – we solved this a while ago, I can’t remember what it was. I believe, again, updating the Keystone packages might have solved it.
If it can help I have solved the problem. It was because I was using an nginx reverse proxy. By check the logs I have found :
2020/05/07 12:34:39 [crit] 20447#0: *6 open() "/usr/local/var/run/nginx/client_body_temp/0000000001" failed (13: Permission denied)
Solved by giving the right permissions on this folder