Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag and drop image uploads in markdown editor #4369

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thomasmaclean
Copy link

@thomasmaclean thomasmaclean commented Jun 20, 2017

Description of changes

Adds drag and drop image upload support for the Markdown editor. The editor will require a URL endpoint to actually perform the upload. An example API route that could work in the URL parameter (using S3 in this case):

exports.upload = (req, res) => {
	if (!keystone.security.csrf.validate(req)) {
		console.log('CSRF failure');
		return res.apiError(403, 'Your csrf is bad and you should feel bad');
	}
	if (req.files && req.files.file && req.params.path) {
		var storage = new keystone.Storage({
			adapter: require('keystone-storage-adapter-s3'),
			s3: { path: '/my-path' },
		});
		storage.uploadFile(req.files.file, (err, file) => {
			if (err) return res.send({ error: { message: err.message } });
			return res.send(storage.adapter.getFileURL(file));
		});
	} else {
		return res.apiError(403, 'No image selected');
	}
};

Related issues (if any)

Fixes #2071. Based on pull request #2508 by @jacargentina.

@thomasmaclean thomasmaclean changed the title Fix 2071 Drag and drop image uploads in markdown editor Jun 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants