javascript - Paste screenshot into a textarea using Paste.js, but how would you transmit it to Rails? -


i'm working on solution allows paste screenshots directly textarea in rails, parsed markdown lateron.

i found neat paste.js library captures clipboard, detects whether string or image pasted, , reacts upon images converting them base64 string can used image.

being is, paste.js offers needed paste simple image tag textarea this:

![some alt text](data:image/png;base64,ivborw0kggoaa...suvork5cyii=) 

but clutter whole textarea, base64 strings can become very, long. i'd inserted placeholder so:

![some alt text](blob:3857c1cf-1a68-4549-bc0d-aa18af25bb82) 

and then, in hidden input field, i'd send base64 data:

<input type="hidden" name="post[content][screenshots][3857c1cf-1a68-4549-bc0d-aa18af25bb82]" value="data:image/png;base64,ivborw0kggoaa...suvork5cyii=" /> 

my question now: how implement on server side in rails? want save them regular files under uploads, store uploads carrierwave.

i don't want them uploaded automatically when pasted, users can cancel when creating or editing post, , don't want upload space cluttered images not in use.

also, don't want images (once saved) removed server again, e.g. when removing reference blog post, blog posts versioned (using papertrail) , references exist in old versions, think it's sensible keep old images.

do think makes sense? or miss something? there limitations don't see (e.g. upload limit of long base64 strings)?

maybe there other libraries doing same? know github issues support feature, couldn't find out how did it, , don't allow pasting screenshots in firefox, either (which supported paste.js).

i had exact requirement blog. thank tip paste.js; implemented , wrote write up.

i used following approach implement it.

  • user pastes image textarea
  • paste.js captures base64/png data
  • ajax payload server
  • server convert jpeg
  • save on server
  • return markdown link front end
  • append markdown link textarea's content

i want change last point can remember location of user's cursor , insert there, opposed appending end.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -