Rails: upload a file OR store a url - ruby-on-rails

I'm developing a form where I want to allow users to either upload a file, or enter a url to an existing file.
The idea is to allow users to attach various 'multimedia' files to entries, some of which may be files from their hard drives (think images, word documents, etc) and some may be urls (youtube videos, images on flickr, etc)
Any ideas on how I can accomplish this? I'm currently using carrierwave to handle file uploads, and it seems to work well, but I want to store url's as well.

What I will probably do is to have a drop down in the file upload form to select if the file is from the disk or from external url.
By default it will set to "from disk", and if they select external url, you could use some AJAX magic and hide the file upload text box and have a text box to use the external url/script etc..
in the table, you can keep another two columns,
1 - external url
2 - file category (external / uploaded file)
by that way you can distinguish the files and how they what to display in the view
HTH

Don't save the url unless you really have too. The thing is that when you save a url, you can't process it to create a thumbnail or multiple styles of the image. Also, when you display the images in a page you will have to make external calls and that can slow down the page or even worse, if the link breaks sometime in the future your users will see an empty image.
Which is also the case with youtube videos. However, with videos you typically want to store and display more information than just the video. You can have two tables - one for videos and one for images. In the video table you have title, desc, author, duration, embed code, thumbnail (image attachment).
You can download any image when a URL is given and save it like a normal file.
Using carrierwave -
#object.remote_image_url = "http://www.foo.com/file.png"
#object.save
In the view, you would have both options, perhaps side by side and you can let them post to different actions. So if a file is selected and posted you save it normally. If a url is entered, then you can check if it's a video site or not - if video, parse out the info using the video_info gem and store it. Otherwise just use the two lines above and save the url image.
Note
My answer doesn't discuss the quality / nature of user inputs. The likely-hood of someone entering an incorrect url is high in my opinion, so you want to wrap attempts to save the url as an image in a begin-rescue block and perhaps using JS limit the video domains to just a few websites which you will be able to parse.

Related

Videos URL structure with nothing but a date in it to keep every video shareable?

what is the approach to store multiple videos from an author in his named folder, but then there are 1-n videos from this author?
YouTube has for every video a complete different URL with an ID. Casual/Older users don't know where they are.
News sites seem use /topic/title-id123
Cnn uses /yyyy/mm/dd/title
To keep this question answerable: What URL structure would you recommend for me?
- every person has some videos without interesting title we could use
- the date from start day to end day is more likely important (2005-12-12 to 2005-12-17)
- every video should be social media shareable, so I think they all need a single URL and can't just be all embedded in /videos/name
Store them however is the best for the backend editor workflow (you didn't mention, how and when new videos are added), in 6.2 you have file abstraction layer, so each file in fileadmin has assigned ID. If you want to make your videos nicely social media sharable, you need to provide additional metadata such as video name and thumbnail etc, so I would suggest building a plugin for this which would take the video ID from the URL and display it with all the additional data necessary.
If you are using EXT:realurl (which I hope you are), you can configure to the video title in the URL, which would look like: /somepage/video/video-title/ or even /somepage/video-title/ . Adding /yyyy/mm/dd/ in the URL only makes sense if you are producing multiple videos every day, otherwise it feels pointless.
for building unique URLs with realurl for news you find solutions to include the uid of the news.
As TYPO3 handles all files with FAl you might use the unique file_sys:uid in your video URL. You might use realurl to generate and resolve URLs like:
/videos/123/title_of_video/

what is the best way to implement interactive book in c#

I can upload large document as pdf file into web page no problem. but i want to use arrows to navigate the book pages not to upload the whole book at once as this may take long.
can any one help how to do this in mvc app with or without database? if database is necessary would Mongodb be a better choice? i do not want people to download the book; they can just read it online?
First you cannot prevent people to download your content if you visually display it BUT you can discourage them by making it difficult to do so.
That being said you wouldn't have a need a database to do what you want to do. You can but it's not necessary. You can simply find some library online that handle PDF such as iTextSharp cut the book in 1 PDF per page with it when it get uploaded so you have bunch of small files.
Then the trick is simple you query the PDF library to load the file Page1.PDF (arbitrary name) extract text format and output as text nicely has HTML. when the person click the link Page 2 then reload the page with the new PDF to use for display.
Doing so prevent the user from seeing or having access to the PDF file itself and if he want to download it all he will have to copy paste every single page manually or by code if he's a dev. Most common user wont go around copy pasting manually 300 pages because of laziness.
What i would personally do is each file uploaded i would create a folder with the name of the book and call the files 1.pdf, 2.pdf .... per page. Like that if i query the listing of directories i get the list of all books, and if i check the count of files in it i know the total page number. That would allow me to run all that without database.

Rails: How to use one form file_field to upload multiple selected files at once?

I'm trying to make an image heavy web app that allows you to upload multiple images. However, I don't want to pollute my site with a bunch of file_fields because it looks ugly and is also inconvenient, since the user has to upload multiple pics one by one like that. Is there a way to make it so that when you click the file_field box that you can select/highlight multiple files at once and upload them all at once? If so, how would I target each uploaded image so that I can display each of them?
Short answer: you can't. field_field just elaborates into input tags of type file which, by specification, can only load a single file at a time.
You can, though, have a look at other solutions which can be fit into a Rails application such as jQuery-File-Upload or Plupload

How should I start this Ruby on Rails app?

I want to create an app in Ruby on Rails that when a user pastes the link of a video, the thumbnail is embedded, and when the user clicks the thumbnail, the video is embedded with ajax. How should I start developing this functionality? I plan on using Embedly. My first question is how do I use it? I've read the documentation, but there are a bunch of different tutorials and I'm not sure which one to use. And specifically how do I get the thumbnail and the video? Also, should I have a separate model for both the thumbnail and the video? Or should the thumbnail be a field in the video table? What should I be storing in my database?
I would really, really appreciate any help.
Embed.ly API gives you a pretty wide range of options. Thumbnail is also included in the return hash. All you need to do is capture the url your users paste, plug it into this API url, and parse the returned hash for the thumbnail image.
You can then easily use the jQuery plugin to generate the embed link when the user clicks on the thumbnail.
$.embedly('http://www.youtube.com/watch?v=LfamTmY5REw',
{maxWidth: 600,
elems: $('#element'),
success: function(oembed, dict){
alert(oembed.title);
});
Note that in this function elems property is where you want your video to be embedded. oembed parameter contains the hash, which includes the thumbnail image link. So you can do everything in this one call. Embed the video as soon as the user pastes the link, and simply hide the embedded video until the user interacts with the thumbnail image.
You should probably save the thumbnail url as a field of the same model as everything else.

Issues with Filemaker IWP working with hyperlinks on images

I have a filemaker database that I need to be able to link records and all associated data (including container field data) to various points placed on a large PDF image, and then make that data appear via instant web publishing when someone clicks on the marker for that area on the PDF. For example the PDF may be an image of a car, and then I would have various close up images of issues with the car and descriptions of those images as records in the database. I would then want to drop points on the base PDF image and when you clicked on those points be able to see the close up images and other data related to those images.
I'm being told this is too much for IWP because:
I need to place the markers outside filemaker via PDF annotation
Filemaker IWP can't handle the number of markers that may be necessary (it could be up to 1,000 on an E sized image.
Does anyone have a work around or explanation why this is a problem?
If I understand correctly, you would like to setup a PDF with links that will open a browser and show data related to what was clicked. Assuming that is the case, the reason this wont work is because IWP does not provide a unique URL for a unique page. For example, here on StackOverflow you can directly link to any question based on its URL:
http://stackoverflow.com/questions/3207775/ -- this question
http://stackoverflow.com/questions/4973921/ -- some other question
IWP uses Javascript and session variables to manipulate the output to the screen, so there is no way to link to a specific section of your IWP site, since the URL is always something like:
http://yoursite.com/fmi/iwp/cgi?-db=YOUR_DB-loadframes -- Product A
http://yoursite.com/fmi/iwp/cgi?-db=YOUR_DB-loadframes -- Product B
http://yoursite.com/fmi/iwp/cgi?-db=YOUR_DB-loadframes -- Product C
Because of the limited nature of IWP, you will not be able to workaround this issue. You'll need to build your own web-interface using the Custom Web Publishing Engine, either using the built-in PHP extensions or some other technology where you invoke the XML publishing API.
I agree with Nate
IWP is the wrong solution to this problem. You'd be better off simply hosting those images on a webserver.
Now here comes the plug, you can use SuperContainer to really simplify the management of the images from FileMaker.

Resources