0

My web app allows users to record their geolocation data. I need to somehow get that geolocation data into a file so I can put it in s3 storage. I have no idea how to go about this, but the controller already has file uploads to s3 set up using paperclip.

Is there some way to generate a file with javascript and then attach that file when the user clicks save? The other option I was thinking is that I could add a bunch of strings to the body using jQuery .data() method, but then I don't know how to attach a string as a file in my rails 3 form.

Any help is appreciated.

1 Answer 1

0

maybe you should try out Amazon's simple db instead of s3 for this? It would be more appropriate than creating files to store data in s3.

Amazon recently released a ruby sdk for their web services, SDB included: https://github.com/amazonwebservices/aws-sdk-for-ruby

Edit: Or better yet, forget using SDB directly. I had forgotten that that SDK includes an implementation of ActiveModel called AWS::Record. Should make this trivial.

I'm assuming you're on Heroku or something and don't have a method of data persistence?

edit: looking quickly at paperclip's assign method, there's a chance this would work.

yourmodel.your_paperclip_attachment = StringIO.new(params[:your_posted_geolocation_data])

Paperclip appears to handle creating a tempfile from the stream.

4
  • Correct, this is on heroku. After looking through the sdk, I found there is a 1000 byte limit for objects and 10gb limit for a domain. Based on this, I believe I need to continue to use S3 for storage. The 'file' I want to save could be any where from 72kb to 10mb. Aug 10, 2011 at 21:02
  • yikes 10mb? Your app could POST the data and you could create a temp file server side and save it as your paperclip attachment, I suppose. You're not going to create a file with JavaScript. Aug 10, 2011 at 21:30
  • I'm not sure what you mean by 'POST the data', but I did come up with a funky work around. I add the data to a hidden text area, and when the form is submitted to the controller I use that nifty StringIO.new(). It works, though is a little hacky. Aug 11, 2011 at 4:29
  • Cool, that's all I meant. POST as in send the data to the server in a POST request, through a form most likely, which is what you did. Glad it worked. Aug 11, 2011 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.