i have app uploads videos less 10mb specified google cloud storage bucket, however, not file greater 10mb.
i know how resumable uploads. not want links documentation, have read of documentation. not help.
i doing in python. understand me resumable upload need authorization token , have no idea how that. 1 me code?
here code post videos < 10mb
class getdata(webapp2.requesthandler): def post(self): data = self.request.get('file') bucketname = self.request.get('bucketname') typeof = self.request.get('content_type') sender = self.request.get('sender') profilevideo = self.request.get('isprofilevideo') file_path = '' = time.time() objectname = try: keytext = open(conf.private_key_path, 'rb').read() except ioerror e: sys.exit('error while reading private key: %s' % e) private_key = rsa.importkey(keytext) signer = cloudstorageurlsigner(private_key, conf.service_account_email, gcs_api_endpoint) subdirectory = 'videomesseagesfrom' + sender if profilevideo == 'true': file_path = '/%s/profile_videos/%s' % (bucketname, objectname) r = signer.put(file_path, typeof, data) else: file_path = '/%s/%s/%s' % (bucketname, subdirectory, objectname) r = signer.put(file_path, typeof, data) self.response.headers['content-type'] = 'application/json' obj = { 'completion' : 'video uploaded' } self.response.out.write(json.dumps(obj))
i pass in file , bucket name. grabs credentials google generated key in project , signs put url, puts me.
def put(self, path, content_type, data): """performs put request. args: path: relative api path access, e.g. '/bucket/object'. content_type: content type assign upload. data: file data upload new file. returns: instance of requests.response containing http response. """ md5_digest = base64.b64encode(md5.new(data).digest()) base_url, query_params = self._makeurl('put', path, content_type, md5_digest) headers = {} headers['content-type'] = content_type headers['content-length'] = str(len(data)) headers['content-md5'] = md5_digest return self.session.put(base_url, params=query_params, headers=headers, data=data)
it making put request content-type headers , that. maybe put check on this, if file larger 10mb somehow edit put method resumable upload, or upload in chunks. however, have no idea how that.
Comments
Post a Comment