【问题标题】:Cannot upload file to Amazon S3 using Boto无法使用 Boto 将文件上传到 Amazon S3
【发布时间】:2014-12-16 00:46:54
【问题描述】:

我正在使用 Flask / Heroku 和 Boto 库。我希望将上传的文件保存在我的 S3 中...

@app.route("/step3/", methods = ["GET", "POST"])
def step3():
    if request.method == "GET":
        return render_template("step3.html")
    else:
        file = request.files['resume']
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            k = Key(S3_BUCKET)
            k.key = "TEST"
            k.set_contents_from_filename(file)
            return redirect(url_for("preview"))

但下面给了我以下...

TypeError: coercing to Unicode: need string or buffer, FileStorage found

【问题讨论】:

    标签: python-2.7 heroku amazon-web-services amazon-s3 boto


    【解决方案1】:

    要编写它,您需要将文件更改为字符串,这意味着您需要在打开后读取它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-20
      • 2012-12-28
      • 2017-08-18
      • 2021-05-21
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多