0

I have a rails app hosted on heroku and a mobile app made with rhodes.

I'd like to send images from the mobile app to my rails app using an HTTP POST request. Since heroku doesn't allow you to store files, I'm using amazon s3.

I can't send the file from heroku to s3 because it takes more than 30 seconds and causes a timeout. I've seen plenty of examples of uploading a file direct to s3 when the user has a form, but this obviously won't work in this case.

I tried using the suggestion here:

rails 3, heroku, aws-s3, simply trying to upload a file to S3 that is POSTed (http/multipart) to our app

but I still get a 503 request timeout.

I don't want to put my amazon s3 keys on the app.

Right now, I feel like my only option is to host my app on EC2 which I would rather not do as I like the simplicity of Heroku.

Also, it seems strange that these uploads would take so long regardless. I'm only posting images from a mobile phone camera, so they're not huge files.

Community
  • 1
  • 1
NielMalhotra
  • 1,375
  • 2
  • 13
  • 22
  • What's the reasoning behind you not wanting to put your S3 keys into your application environment (you don't want to put them in the code, that's for sure) – Neil Middleton Feb 29 '12 at 23:33
  • Maybe I wasn't clear. I'll obviously have my s3 keys in my heroku app. I just don't want them on the mobile app. I thought about having the mobile app download the s3 keys from the heroku app temporarily, but that still makes it pretty easy for the keys to be stolen. – NielMalhotra Mar 01 '12 at 00:05
  • I think putting your S3 keys in your mobile app is the only answer here. – Neil Middleton Mar 01 '12 at 13:50

2 Answers2

2

I was getting the same error in a project in my job. Some people says that the only way to solve this is by uploading files directly to the S3 bucket. This is difficult in our case, because we are using Paperclip Gem for Rails and different size versions of the image.

Some other people says that "The Heroku timeout is a set in stone thing that you need to work around. Direct upload to S3 is the only option, with some sort of post-upload processing required", so I recomend to do the next:

Maybe this is not a solution but, it could be very useful, it was for me in a Rails App:

Worker Dynos, Background Jobs and Queueing

Perhaps you should move this heavy lifting into a background job which can run asynchronously from your web request.

Regards!

Community
  • 1
  • 1
0

So I finally figured out how to do this.

After lots of back and forth with AWS reps and Cloudfiles reps and pulling my hair out, I realized it would be a lot less work to just get another rails server that could write to the filesystem.

So, I started another rails app on openshift. It's just as easy as Heroku to get started (in fact, I might consider moving my rails app there, but it's too new for my taste right now and doesn't have the community around it that Heroku does).

Then, I just had to have communications between my two rails apps.

I know it's not the best/scalable/elegant fix, but it got the job done, and that's what matters in the end!

NielMalhotra
  • 1,375
  • 2
  • 13
  • 22