将视频上传到GAE Blobstore并在上传时获取输入

时间:2013-07-21 21:51:54

标签: python google-app-engine video blobstore

我正在使用Python中的Google App Engine,我希望用户能够通过关注basic example来上传视频,但我希望能够让用户添加其他内容有关视频的信息,例如标题和类别以及上传时的摘要。有什么方法可以使上传异步,这样用户就不必等待视频上传的全部时间了吗?

我知道create_upload_url_async()方法,但这不能解决我的问题。

现在我有以下内容上传和服务,但我想做一个中间步骤,用户可以在上传时优先在与UploadHandler相同的屏幕上添加信息。

class VideoHandler(BlogHandler):
    def get(self):      
        user = self.get_user()
        upload_url = blobstore.create_upload_url('/uploadingvideo')
        self.render('videohandler.html', user=user, upload_url=upload_url)

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
  def post(self):
    upload_files = self.get_uploads('file')  # 'file' is file upload field in the form
    blob_info = upload_files[0]
    self.redirect('/serve/%s' % blob_info.key())

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
  def get(self, blob_key):
        blob_key = str(urllib.unquote(blob_key))
        if not blobstore.get(blob_key):
            self.error(404)
        else:
            self.send_blob(blobstore.BlobInfo.get(blob_key))

如果您需要,我很乐意提供更多信息。

1 个答案:

答案 0 :(得分:0)

这让我很烦恼太多了。解决方案是围绕blob表单构建表单。

以下是google关于如何向blob商店提交数据的示例。

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
  def post(self):
    upload_files = self.get_uploads('file')  # 'file' is file upload field in the form
    blob_info = upload_files[0]
    self.redirect('/serve/%s' % blob_info.key())

只需删除代码底部的自我重定向位,然后添加一些代码来处理表单。

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
  def post(self):
    upload_files = self.get_uploads('file')  # 'file' is file upload field in the form
    blob_info = upload_files[0]

greeting = Greeting()

if users.get_current_user():
greeting.author = users.get_current_user()
greeting.video = str(blob_info.key())
greeting.content = self.request.get('content')  
greeting.put()

您的django模板中的表单应如下所示:

form action="{{ upload_url }}" enctype="multipart/form-data"  method="post">

textarea name="content" placeholder="write something about this video.."  tabindex="1" rows="2" cols="40"></textarea>

input name="file" type="file" >

input name="submit" type="submit" value="Submit"  />

/form>

你有它。希望这有帮助