AppEngine:从获取的 URL 上传到 S3 时仅获取 1KB

发布于 2024-10-20 17:38:56 字数 1332 浏览 3 评论 0原文

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

我搜索并尝试了不同的方法,但没有一个有效。这是由用户单击按钮触发的类。

` class 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 的任何内容,...有什么建议吗?

提前致谢。

I´m trying to upload a file which is fetched from a server. But when the fetched file is bigger than 1MB there will be only a 1KB small file saved at S3. When it´s smaller than 1MB, the file will be saved properly.

I ´ve searched and tried different ways, but none off them is working. Here is the class which is triggered by the user clicking a button.

`
class 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)`

I just don´t have any clue why this happens. Something with my code, some AppEngine restrictions, anything with boto, ... Any suggestions?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恋你朝朝暮暮 2024-10-27 17:38:56

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

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

The maximum request size on app engine is 1mb for urlfetch. I'm guessing your S3Connection class uses that to do the actual transfer.

Responses can be up to 32MB, that's why the download works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文