0

我有一个基本的 Sinatra 应用程序,它将文件上传到 S3,然后通过从 S3 下载文件、转换为哈希然后将其放入数据库来对文件进行一些分析。

目前我有脚本工作:文件上传,下载和分析但是,大约在分析的一半,再次调用 POST 方法,因此文件被重新下载并开始分析。

脚本如下所示:

require 'sinatra'
require 'aws'
require "./redo.rb"

get '/' do
  return %Q{
    <form action="upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
    Upload a file for processing:
      <div>
        <input type="file" name="file" value="" id="file">
      </div>
      <div>
        Email address: <input type="text" name="email" value="" id="email">
      </div>
      <div>
        Subscribe? <input type="checkbox" name="subscribe" checked="checked" id="sub">
      </div>
      <div>
        <input type="submit" value="Upload &uarr;">
      </div>
    </form>
  }
end

post '/upload' do

  customer_id = SecureRandom.uuid

  emailaddress = params[:email]
  subscribe    = params[:sub]
  file         = params[:file][:tempfile]
  filename     = params[:file][:filename]



       url = uploadtoS3(file, filename, customer_id)

      return url
    end

使用 redo.rb 中的方法,如下所示:

def uploadtoS3(attr_file, attr_filename, attr_customerID)
  puts "in uploadtoS3"
  bucket = $s3.buckets.create("#{attr_customerID}")
  obj = bucket.objects["#{attr_filename}"]
  obj.write(Pathname.new(attr_file.path))

#Call analysis methods here...

urlpointer = "https://#{bucket.name}.s3.amazonaws.com/#{attr_filename}"
return urlpointer
end

为什么多次调用 /POST 方法?

4

0 回答 0