用于Python的GAE上的自动并行复合上传

时间:2013-12-10 05:12:12

标签: python google-app-engine upload google-cloud-storage gsutil

我想使用gsutil的自动并行复合上传从Google App Engine上传到云存储。 我想让你告诉我有两个。 以上内容是否有可能。 如果可能,以下来源的内容不足。

#!/usr/bin/python2.7
# -*- coding: utf-8 -*-

import logging
import webapp2
import time
from google.appengine.ext import db
import boto

GOOGLE_STORAGE = 'gs'
LOCAL_FILE = 'file'
TEST_BUCKET = 'test'

class UploadHandler(webapp2.RequestHandler):
    def post(self):
        config = boto.config
        config.add_section('Credentials')
        config.add_section('GSUtil')
        config.set('Credentials', 'gs_access_key_id', 'XXXXX')
        config.set('Credentials', 'gs_secret_access_key','XXXXX')

        config.set('GSUtil', 'parallel_composite_upload_threshold', '9M')

        config.set('GSUtil', 'parallel_composite_upload_component_size', '3M') 

        text = self.request.get('file')

        uri = boto.storage_uri(TEST_BUCKET, GOOGLE_STORAGE)
        try:
            header_values = {"x-goog-api-version": "2","x-goog-project-id": "XXXXX"}
            uri.create_bucket(headers=header_values)
            print 'Successfully created bucket "%s"' % 'TEST_BUCKET'
        exce`enter code here`pt boto.exception.StorageCopyError, e:
            print 'Failed to create bucket:',e

        filename = 'test.txt'
        dst_uri = boto.storage_uri(TEST_BUCKET + '/' + filename, GOOGLE_STORAGE)        
        dst_uri.new_key().set_contents_from_string(text)

0 个答案:

没有答案