uploading to google drive with paperclip in Rails - ruby-on-rails

Hello there i am new to using the google drive gem and i do not know how to use it with paperclip to upload photos to the google drive. Its a simple rails application that i am developing that uploads photos to google drive, is there any rails application example that i can use to get me started with the gem or can any body present an example here to aid we beginners using the google drive gem. Paperclip should be used to upload the files. Thank You

You'd likely have to implement a storage adapter for Paperclip. Take a look at something like https://github.com/dripster82/paperclipdropbox as an example. In that case, it looks like it only supports uploading to a single pre-authorized account. If that's OK, then modifying that to talk to Google Drive instead of Dropbox should be straightforward. If you need to support multiple users, you'd have to make sure the right credentials are being used for the current user.
Anyway, the paperclip docs are likely the best place to get started :)

Related

Loop through PDFs in Google Drive, display on Rails site

I have a client storing PDFs in a public Google Drive folder. I would like to loop through that folder and display a clickable link (i.e. filename) on my Rails web page. I'm reading through the Google Drive API information here:
https://developers.google.com/drive/api/v3/about-sdk
Can anyone recommend additional methods or tutorials that might be useful for a rails app?
Alternatively, would it be better to use Amazon S3 and Paperclip EDIT. 5/25/18 Paperclip is deprecated. Active Storage has been recommended for file upload for file upload and storage? (Not sure I want to go this route. I think my client wants to create his file in Drive and voila! It appears on his web page. Just not sure that's possible.)
Newbie programmer here. Thanks.
To get a list of files from a Google Drive folder you'll need to use the Files:list method from the Drive API
In the Files:list page I generally find it useful to use the "Try this API" to get sample responses from the Google API.
To list all the files for a given Folder ID you'll want to use the following syntax for the q parameter:
'<folder_id_here>' in parents
For example:
'1Cz3KdJlzMj-vmN6OMd_nQyUKWlkdsfujo' in parents
For Ruby example specific to the Drive API, see:
https://developers.google.com/drive/api/v3/folder
For complete Ruby examples, maybe check out the following:
https://github.com/google/google-api-ruby-client-samples

upload image to cloudinary and save only the url in database

I want to create a photo gallery in Rails displaying the photos from Cloudinary. How to save the urls in the database to display them, or is there any other option to do it without saving the urls?
Many Thanks,
Imre
Cloudinary has a pretty good documentation on how to integrate its service into a Rails app. Start by adding the gem to your gem file.
http://cloudinary.com/documentation/rails_integration
What you describe: "...save only url to the Database' is basically the principle of their service. You save the image itself in their cloud and the gem provides you a #model.name_url helper inside your app as well as a url for the image.
They offer different options of setting up their cloud service with Ruby and Rails, and much can be found in their docs.
Cloudinary also has a good Doc on how to integrate carrierwave and cloudinary together for image upload.
http://cloudinary.com/documentation/rails_carrierwave

Uploading pdf files stored in iphone to server in ios

I am making an iphone application which is pretty much like forum. People can ask question and upload a pdf/doc file along with the question. Is there a way to access the pdf/doc file in iphone when user clicks upload button and send the file to server?
I have implemented the feature for image for which I used UIImagePicker to pick the image and send it to the server with http request. But I am completely lost and have no idea how to handle pdf/doc files in same manner.
Any help/suggestion really appreciated. Thanks in advance.
If you want to upload PDF and Doc files, then you can integrate Dropbox and Google Drive in your app and then select the files ,as Apple does not have centralised storage. If you notice Apple also chooses the documents from Google Drive while composing a mail.
So implementing and integrating google drive and Dropbox would be a good option.
Here is the link for Dropbox https://www.dropbox.com/developers-v1/core/sdks/ios
Here is the link for Google Drive https://developers.google.com/drive/ios/quickstart
Implementing Google drive is a bit hard but dropbox is quite simple.
Wish it saves your time. All the best!
I think you are looking for a combination of two things (both have been discussed here before and I include the links below).
(1) store a PDF. There are many options but the best way is to allow coredata to save outside the persistent store. Then store the reference to the file in core date. See: Insert a PDF file into Core Data?
(2) send the file to the server. There are many options for this as well. The fastest is probably to use a wrapper library such as ASIHTTPRequest. See: File Upload to HTTP server in iphone programming

Storing images not as part of app

I am building my new site and have a small group of images I want to display on the site.
They are not images to do with styling so it feels wrong to store them within the app/assets directory
I don't wish to put them on my Flickr account which builds by apps gallery as they are not that type of image.
I currently have them stored on an Amazon S3 bucket and link to them from there.
is there a better way. What way would you guys choose?
If I am already using the best way, is it worth linking to them using the standard url Amazon provides me with or should I direct one of my URL's to that point?
Your choice for Amazon S3 seems fine to me, and no, you should not change the standard URL's Amazon provides you with. Advantage is that your own web server is not bothered by the image URL's anymore!
I have a similar website storing "dynamic" pictures, and I keep them on cloudinary, which is a similar site. Your source directory should not in general store these "dynamic" pictures. They only consume disk space, and sites like Amazon S3 and Cloudinary are made just for that!

Rails uploading multiple photos onto Amazon S3

I currently use the Paperclip gem to attach photos onto certain models in my project. However, I have a blog model where I use multiple photos per instance of the blog.
I'm looking for a solution where I can just upload photos into a folder on Amazon S3 and refer to these photos later using the HTML anchor tags. I don't want to attach the photos to any model.
Any suggestions?
I haven't done this myself, but I would look for the solution here http://amazon.rubyforge.org/ I believe paperclip uses it behind the hood.

Resources