【问题标题】:AppEngine: Getting only 1KB when uploading from an fetched URL to S3AppEngine:从获取的 URL 上传到 S3 时仅获得 1KB
【发布时间】:2011-07-10 13:58:43
【问题描述】:

我正在尝试上传从服务器获取的文件。但是当获取的文件大于 1MB 时,S3 中只会保存一个 1KB 的小文件。当文件小于 1MB 时,文件将被正确保存。

我已经搜索并尝试了不同的方法,但它们都不起作用。这是由用户单击按钮触发的类。

` 类 Fetch_by_button(webapp.RequestHandler):

def get(self):
    #1. fetch the file
    try: 
        result = urlfetch.fetch('http://someurl.com/music.mp3') # file with 2MB
        #result = urlfetch.fetch('http://anotherurl.com/document.pdf') #file with 900KB is working
    except DownloadError:
        print("URL fetch doesnt work properly")

    #2. search datastore UserData-model by userobject to get s3 credentials
    usr = users.get_current_user()
    query = UserData.gql("WHERE account =:1", usr)
    qr = query.get()

    #3. establish connection to s3
    conn = S3Connection(qr.s3_accesskey, qr.s3_secret_accesskey)

    #4. create bucket
    ak_lowercase = str.lower(str(qr.s3_accesskey))
    individual_bucket_name = ak_lowercase + '_' + usr.nickname()
    bucket = conn.create_bucket(individual_bucket_name)

    #5. generate key and assign to already created bucket
    k = Key(bucket)

    #6. name the key by some examplary filename
    k.key = 'justsomefilename'

    #7. save the correspondent value to the created key
    k.set_contents_from_string(result.content)`

我只是不知道为什么会发生这种情况。我的代码有什么问题,AppEngine 有什么限制,boto 有什么问题……有什么建议吗?

提前致谢。

【问题讨论】:

    标签: python google-app-engine amazon-s3 boto urlfetch


    【解决方案1】:

    对于 urlfetch,应用引擎上的最大请求大小为 1mb。我猜你的 S3Connection 类使用它来进行实际传输。

    响应最大可达 32MB,这就是下载有效的原因。

    【讨论】:

    • S3Connection 类来自 boto 库并使用 httplib 中的 HTTPConnection 类。然而,boto 用于创建连接和发送数据的方法 - 似乎 AppEngines urlfetch 的 1MB 限制对每种传出请求都有影响。如果没有人可以否认这一点,或者提出一种解决方法/解决方案......我将不得不重新考虑我的应用程序:(
    • @Michael 没错。 urllib、httplib 等都是 App Engine 生产环境中 urlfetch 的模拟。
    • 如果 GAE 只是将上传限制提高到 5MB,一切都会变得很花哨,因为 S3 支持多部分上传:bit.ly/fUynir
    猜你喜欢
    • 1970-01-01
    • 2015-05-30
    • 1970-01-01
    • 2012-06-14
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 2015-07-06
    相关资源
    最近更新 更多