Accept pasted image in Rails - ruby-on-rails

I'd like my users to be able to upload an image by pasting it into a form.
Is this possible somehow with Rails?
I'd like to do this safely and limit to a single picture upload, not a completely open textarea.
UPDATE:
I'm looking for something like http://pasteboard.co/ that I can add into a form in a Rails app.
Also, with a paperclip hook like https://github.com/galetahub/ckeditor would be nice

Although I don't have a specific answer (copy & paste), I do have an answer regarding how to implement the uploading within the DOM:
JQuery
If you use something like jquery-file-upload, you'll be able to incorporate a GUI-based upload process to Rails
I think your question can be answered by taking this technology & applying to the specific element where you'd like to "copy & paste" the image
You can drag & drop images from your system into the example above. This is very similar to the copy & paste functionality you're seeking. I would personally look at this technology, and then apply it to the copy & paste procedure
WYSIWYG
You've referenced GMail as a great example of this -- but you have to remember they're allowing you to paste into a WYSIWYG editor
This is very important, as the upload image element will be handled through the WYSIWYG. You may be able to use this resource to help:
Wysiwyg with image copy/paste

Related

Add-on for Submitting File from Clipboard

Is There A Browser-Add-on That Can Create A Temporary Txt File From My Clipboard And Populate The File Submit Dialog?
Guide for firefox:
Get the data from your clipboard with this: paste data from clipboard using document.execCommand("paste"); within firefox extension
Now you can either create a temporary file with something like OS.File: https://developer.mozilla.org/en-US/docs/JavaScript_OS.File/OS.File_for_the_main_thread
Or create a object with something like window.createObjectUrl.
Then assuming the file submit dialog is prompted by a html5 uploader, then you should just set value of that html5 dialog box there are other ways though too, like mozSetDataAt, mozSetFileArray etc, search github for these keywords shows excellent examples:
https://github.com/search?l=javascript&q=mozSetDataAt&type=Code&utf8=%E2%9C%93
https://github.com/search?l=javascript&q=mozSetFileArray&ref=searchresults&type=Code&utf8=%E2%9C%93
You might need to use the mimeType of application/x-moz-file not sure. Definitely experiement with it and share your solution, and ask for help along the way. This is fun stuff.
There are probably other smarter ways to attach into a input type=file, i was trying to do it the other week. I would also be interested if someone else could share some solutions to actually trick the file input element to think the native file dialog was actually used, maybe using XPCOM.

Embed PDF in a website, allow user to modify editable fields in PDF, and save back to the server

I am writing a Program in Rub On Rails 4.x and I have to take PDF files with defined fields that can be filled out, fill in data from a form submission(This part is DONE!), and lastly allow the user to modify the saved PDF file on the server and overwrite said PDF after making their modifications.
Like I said I have already gotten the PDF files filled out with what has been submitted in the form through pdftk . What I now need to do is provide a server side editing capability to the said PDF files on server generated from the first step of the process.
I have seen similar posts but none wanting to do the same thing I do. If I am wrong links would be great. Thanks in advance for all your help!
After lots of digging and research here is what I have found to be the facts surrounding this issue and implementing a program to allow embedding the PDF file, editing it, and saving it back to the server. This process would be great however from what I can tell there is nothing out there that really does this for Ruby On Rails. To quote #Nick Veys
Seems like you need to find a Javascript PDF editor you can load your PDF into, allow the user to modify it, and ultimately submit it back to the server. Seems like they exist, here's one for ASP projects
You are correct but still wrong in the sense that yes there is one for ASP projects however that is Microsoft Based, yes I know that it can run on Linux environments through Mono. However to the point it would appear in this instance that a Ruby On Rails specific solution is indeed needed.
The solution that we have come up with is as follows
1. Use a PDF editing package in the linux repositories like PDFtk
2. You then render a page with the PDF embeded on one side and a form representing the live fields in the PDF to take input.
3. Once submitted you use PDFtk to write the values into a new template PDF file and overwrite what was previously stored.
This requires a few additional steps to process the data than I really care for myself. However it is the best solution that our team could come up with, without bleeding the project budget dry for just 1 piece of functionality.
I hope this helps anyone else looking to do the same thing in Ruby On Rails.
I have done something like this using my company's .NET product. It can also be done using its Java version too.
http://www.gnostice.com/nl_article.asp?id=255&t=Save_Form_Submit_Data_Back_To_Original_PDF_Document_In_NET

iOS // show html -> rich text

What is the best way to show html -> rich text in iOS?
The problem is that some images from this text should be available offline, so I can't use a simple UIWebView.
Ideally I want to show just html with an ability to replace some special tags with other controls (UIImageView etc). I don't need to download this images from html. Both images and html will be downloaded with issues. Just need to manage the layout.
Core Text is not suitable, because to use it I'll need to parse this html manually. It should be a simpler way.
This has to be supported by iOS 6, so I can't use anything new from iOS 7.
I've seen this question. Doesn't look like this OmniGroup framework will work for me.
RTLabel doesn't support everything, what I want to have.
DTCoreText looks good, but it's not free (don't want to show their license text).
Maybe it's another cool fremework, which I didn't find yet?
Have tryed
https://github.com/mwaterfall/MWFeedParser/blob/master/Classes/NSString%2BHTML.h
This will simply give string out of html. It might not be exactly what you are looking for but hope this will solve part of your problem.
But this will not solve your offline image viewing.
For image
https://github.com/rs/SDWebImage
Will do a async download and cache image.

Using Your Own Text Editor On a Server

Are there any hosting providers which allow you to use your own text editor to edit hosted files? At the moment, I'm using Namecheap and I can only edit hosted files through their code editor which means I need to edit the files locally and then upload them if I want to use my own text editor. I'd really like to develop a site directly on the server so skipping this step would save quite a bit of time.
Specifically, I'd like to use Sublime Text 2. Google didn't help so I'm hoping someone hear could point me in the right direction.
Thanks.
It looks like EasyEditors might have what you need. It appears that you can edit the files on their site.

textarea that was using plain text with option of markdown or textile filter now needs images

My clients can enter text into textarea and have the option to use the markdown or textile filters for each textarea.
With some models (articles, newsletter, etc) they can upload images to associate with the model, which are displayed in a column next to the text of the text.
This worked fine for a while, but they have now told me that the want the ability to put the images INSIDE the text a specific positions.
What is the best way to go about this? I suppose I may have to use a wysiwyg for this, but would rather not. And how would this work for images which are not yet on the server, etc?
There are different directions you could go to:
Follow the path of Confluence, which released in their new version 4.0 a rewritten WYSIWYG editor, that stores as source XHTML, not any more wiki markup.
Leads to an update of all pages when migrating.
Was pretty difficult to implement. I do not know if they use any more the TinyMCE editor of previous versions.
Follow the format of markdown how to include images in your source format. So by typing: This is my text. !image.png! The inline image shows ..., you will have a format that is understandable.
You have to expand the interpretation, so that the !<filename>! will be mapped that is stored locally anyway.
You have to add clear-up dialogs for the images that are yet not known, so doing bulk uploads ...
You may provide a drag area on your view, that then shows the filename and gives examples how to include that inside the text area.
Go for something in between, by allowing users to drag images inside the editor. There are plugins written in Javascript that allow you to do that, e.g. UI Draggable for jquery
I have no idea how to integrate that image inside the text editor. Overlay?
So the second one is the easiest, and the user knows how to do it. If they only decide that this is the solution they want to have :-)
I think I'm going to use a combination of #2 above, and the Liquid templating engine.

Resources