轨道3,Heroku的,AWS-S3,无非是想将文件上载到张贴(HTTP /多部分),以我们的应用程序S3 [英] rails 3, heroku, aws-s3, simply trying to upload a file to S3 that is POSTed (http/multipart) to our app

查看:112
本文介绍了轨道3,Heroku的,AWS-S3,无非是想将文件上载到张贴(HTTP /多部分),以我们的应用程序S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序托管在Heroku的,所以没有本地文件存储。

Our app is hosted at Heroku, so no local file storage.

我们正在使用不保存它创建了一个WAV第三方API,它帖子的文件(HTTP /多部分)回到我们的应用程序。它们提供样品code为简单的发送文件到S3。在code,他们提供(下同)不on Rails的3 + Heroku上运行。我怀疑有一些不同的语法来指定输入文件和临时文件从中读出。 (在code最初是为西纳特拉我不知道老 [:文件名] [:临时文件] 是对,所以我把他们赶走,并采取了猜测的语法是这个东西用它视为是怎样的?)

A third party api we're using doesn't store a WAV it creates, it POSTs the file (http/multi-part) back to our app. They provide sample code to 'simply' send that file on to S3. The code they supply (below) doesn't run on Rails 3 + Heroku. I suspect there's some different syntax for specifying the input file and temp file from which we read. (The code was originally for Sinatra. I have NO idea what the old [:filename] and [:tempfile] were for so I removed them and took a guess the syntax was something like this using Tempfile?)

  def post_audio_to_s3
    puts "*** POST_AUDIO_TO_S3 PARAMS:" + params.inspect

    con = AWS::S3::Base.establish_connection!(
      :access_key_id     => 'MYKEY',
      :secret_access_key => 'MYSECRET')

    puts "** CON='#{con.inspect}'"

    snd = AWS::S3::S3Object.store(params[:filename], 
                        Tempfile.open(params[:filename]).path, 
                        'bb_audios')
    puts "** SND='#{snd.inspect}'"

更新:几乎工作,但零长度的文件创建。排序我挥舞着周围不知道如何使用它视为档案,但我加了要求临时文件到控制器类和修改的S3存储产品线以上。

UPDATE: Almost works ,but zero length file created. I'm sort of flailing around with no idea how to use the Tempfile, but I added require 'tempfile' to the controller class and modified the S3 storage line to the above.

这整个后一个文件到Heroku的/它视为事已了我的大脑冰镇...任何想法将AP preciated。对于一件事......我不知道那里的数据来自......我不应该看到的东西,除了文件名,当我检查PARAMS如果它被发布到应用程序?

This whole POST-a-file to Heroku/Tempfile thing has my brain iced... any ideas would be appreciated. For one thing... I have no idea where the DATA comes from... shouldnt I see something besides the filename when I inspect the params if it's being POSTED to the app?

推荐答案

答案是如下。我们必须从文件名更改URL参数=来= MyFileName的,因为魔术导轨自动使用文件名为发布的数据,以便他们在PARAMS重踏在彼此[]。

The answer was as follows. We had to change the url parameter from filename= to myfilename= because the rails magic automatically uses 'filename' for the POSTed data so they were stomping over each other in the params[].

openme = params['filename'].tempfile.path

snd = AWS::S3::S3Object.store(params[:myfilename], 
                        File.open(openme), 
                        'MYBUCKET')

这篇关于轨道3,Heroku的,AWS-S3,无非是想将文件上载到张贴(HTTP /多部分),以我们的应用程序S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆