markdown-editor icon indicating copy to clipboard operation
markdown-editor copied to clipboard

Image Upload using Drag & Drop

Open praveenscience opened this issue 9 years ago • 17 comments

Is it possible like how StackOverflow or the current GitHub GFM MD Editor does?

Attach images by dragging & dropping, selecting them, or pasting from the clipboard.

praveenscience avatar Jun 02 '15 13:06 praveenscience

I was thinking about that literally this morning actually. It's something I'd very much like to add, but then it would require setting up a storage backend somewhere. That could be Amazon S3 for example, and I've already got some code written for something like that. The problem then is figuring out how to not make that vulnerable to abuse - I can't afford to let anyone upload anything they like to an S3 bucket under my account, because then people could use it for sharing dodgy files, or upload giant 500GB files that'd make it impossible for me to afford / maintain.

It's a tricky one. It's something I'd really like to do, but it'd need to be done right if I do it at all.

jbt avatar Jun 02 '15 14:06 jbt

Throw them to imgur's api c: On Jun 2, 2015 7:39 AM, "James Taylor" [email protected] wrote:

I was thinking about that literally this morning actually. It's something I'd very much like to add, but then it would require setting up a storage backend somewhere. That could be Amazon S3 for example, and I've already got some code written for something like that. The problem then is figuring out how to not make that vulnerable to abuse - I can't afford to let anyone upload anything they like to an S3 bucket under my account, because then people could use it for sharing dodgy files, or upload giant 500GB files that'd make it impossible for me to afford / maintain.

It's a tricky one. It's something I'd really like to do, but it'd need to be done right if I do it at all.

— Reply to this email directly or view it on GitHub https://github.com/jbt/markdown-editor/issues/29#issuecomment-107976042.

thorsummoner avatar Jun 02 '15 14:06 thorsummoner

Good shout, having quickly looked at their docs it looks like it should be possible. I shall investigate :)

jbt avatar Jun 02 '15 15:06 jbt

@jbt Can I implement it and do a pull request? Forget about the SSL, Security, Storage, etc.. We don't need to use it in the demo! Or, we can have a cron job that clears all the images, with strict type-checking, or at least we'll use imgur's API.

praveenscience avatar Jun 02 '15 18:06 praveenscience

Yeah if you can figure it out that'd be awesome! I quite like the idea of using imgur api, at least so that it can work on https://jbt.github.io/markdown-editor without any extra backend, but maybe it can be written in such a way that the upload destination could be swapped out without changing too much.

The way I quickly had it figured in my head was something like this:

  • Some extra logic in the drop evt handler that checks if the drop is a text file or an image and doing a readAsArrayBuffer for images. Likewise something in a paste event (no idea how that works with CodeMirror unfortunately).
  • Inject placeholder ![Uploading something placeholder text]() into source text at current cursor position
  • Some kind of function like uploadImage(fileName, arrayBuffer, contentType, callback) where callback is function(error, uploadedSrc){} - then that can take care of any auth necessary for wherever the img is being uploaded, and could easily be swapped out based on storage backend
  • Once image is uploaded, go back and replace the ![Uploading something placeholder text]() with ![fileName](uploadedSrc)

Anyway, that's just my thoughts on how I was planning to go about implementing it, might be useful. I know JS Bin has the same kind of functionality - dunno if that'd be useful as inspiration

jbt avatar Jun 02 '15 21:06 jbt

Sure... Lemme try it out. Also good idea would be Ctrl + V handler! What do you say?

praveenscience avatar Jun 02 '15 21:06 praveenscience

Definitely - I think if you listen on the paste event you should be able to grab the img from there with event.clipboardData - this is where jsbin does it I believe

jbt avatar Jun 02 '15 21:06 jbt

Ah... There are a lot of tools for that! Don't worry. I'll take care... I have started working on it.

praveenscience avatar Jun 02 '15 21:06 praveenscience

Guess I will deliver it by Sunday. Is it okay for you? I will make a pull request after that!

praveenscience avatar Jun 05 '15 00:06 praveenscience

Are there any news about this feature? When I have tried to Drag'n'Drop image to demo version - browser crashed.

soar avatar Nov 04 '15 16:11 soar

@soar Yes, I have the problem of browser conflicts... Chrome crashes, and it doesn't work in IE.

praveenscience avatar Nov 04 '15 19:11 praveenscience

@praveenscience Any news ? :-D

daimajia avatar Mar 10 '16 14:03 daimajia

@daimajia Hey buddy. I guess we all got busy with our other works. :disappointed: I will rework on this soon. :smile:

praveenscience avatar Mar 13 '16 12:03 praveenscience

@praveenscience I can understand, looking forward to the new feature. :+1:

daimajia avatar Mar 13 '16 12:03 daimajia

@praveenscience is it possible to share your existing work and I can pick up from where ever it is.

greenlaw110 avatar May 15 '16 01:05 greenlaw110

@greenlaw110 Hey that would be awesome... Will send you whatever I have. I am in a different country as when I started it before. So I don't have all the files with me.

praveenscience avatar May 15 '16 02:05 praveenscience

@praveenscience I've already done with image copy/paste, but in my project which borrow the idea from this project, but rewrite it using riot:

https://github.com/actframework/act-dockit/tree/master/src/main/resources/dockit/editor

It is part of a Java project but can be used separately if you want to write the server in whatever language.

Here are some screenshots:

image

image

image

greenlaw110 avatar May 17 '16 10:05 greenlaw110