将视频上传到谷歌应用引擎blobstore

编程入门 行业动态 更新时间:2024-10-07 19:26:33
本文介绍了将视频上传到谷歌应用引擎blobstore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图将视频文件与一组属性相关联,但似乎无法让用户以一种形式完成所有操作 - 命名视频,提供说明并回答一些问题,并上传

  • 以下是我想要执行的步骤: >用户将获得一个页面,该页面包含一个包含以下字段的表单:名称,描述,文件选择器。
  • 文件被存储为一个blob,并且id会与名称和描述一起记录。
  • 有没有人有这样做的例子,我可以从中学习或者可以指点我的教程?

    感谢并抱歉发表一个新问题!

    解决方案

    这里是我用来上传图片并将它们与文章关联的代码。最棘手的是获取文章ID到达上传处理程序,我通过将文件名设置为文章ID来解决该问题。

    from lib从lib.urllib2_file导入urllib2_file import UploadFile 此视图提供队列中的任务 def article(request): article = Article.objects.get(id = form.cleaned_data ['article']) try: image = StringIO(urllib2.urlopen(image_url).read()) except(urllib2.HTTPError,DownloadError): article.parsed = True article.save() else: image = UploadFile(image,'。' .join([str(article.id),image_url.rsplit('。',1)[1] [:4]])) upload_url = blobstore.create_upload_url(reverse('Articles.views.upload' )) 尝试: urllib2.urlopen(upload_url,{'file':image})除了(DownloadError,Requ ($ status): pass return HttpResponse(json.dumps({'status':'OK'})) def upload(request): if request.method =='POST': blobs = get_uploads(request,field_name ='file',populate_post = True) $ b $ article = Article.objects.get(id = int(blobs [0] .filename.split('。')[0])) article.media = blobs [0] .filename article.parsed = True article.save () return HttpResponseRedirect(reverse('Articles.views.upload')) else: return HttpResponse('meow') def上传(请求): if request.method =='POST': blobs = get_uploads(request,field_name ='file',populate_post = True) $ b $ article = Article .objects.get(id = int(blobs [0] .filename.split('。')[0])) article.media = blobs [0] .filename article.parsed = True article.save() return HttpResponseRedirect(reverse('Articles.views.upload')) else: return HttpResponse('meow') #这个服务的图像 def image(request): blob = BlobInfo.gql(WHERE filename ='%s'LIMIT 1%request.form.cleaned_data ['id']) [0] return HttpResponse(BlobReader(blob.key())。read(), content_type = blob.content_type) pre>

    您还需要 http ://fabien.seisen/python/urllib2_file/

    I'm trying to associate a video file to a record with a bunch of properties, but can't seem to allow the user to do everything in one form - name the video, provide description and answer some question, AND upload the file.

    Here are the steps I'd like to perform:

  • User is served with a page containing a form with the following fields: Name, Description, File selector.
  • The file gets stored as a blob and the id gets recorded together with name and description.
  • Does anyone have any examples of doing this I could learn from or a tutorial you could point me to? The one from google only shows uploading the file and getting redirected to it.

    Thanks and sorry for a newbish question!

    解决方案

    Here's the code I'm using to upload images and associate them with articles. The toughest bit was getting the article id to get to the upload handler, I solved it by setting the file name as the article id to get around the problem.

    from lib import urllib2_file from lib.urllib2_file import UploadFile # this view serves a task in a queue def article(request): article = Article.objects.get(id=form.cleaned_data['article']) try: image = StringIO(urllib2.urlopen(image_url).read()) except (urllib2.HTTPError, DownloadError): article.parsed = True article.save() else: image = UploadFile(image, '.'.join([str(article.id), image_url.rsplit('.', 1)[1][:4]])) upload_url = blobstore.create_upload_url(reverse('Articles.views.upload')) try: urllib2.urlopen(upload_url, {'file': image}) except (DownloadError, RequestTooLargeError): pass return HttpResponse(json.dumps({'status': 'OK'})) def upload(request): if request.method == 'POST': blobs = get_uploads(request, field_name='file', populate_post=True) article = Article.objects.get(id=int(blobs[0].filename.split('.')[0])) article.media = blobs[0].filename article.parsed = True article.save() return HttpResponseRedirect(reverse('Articles.views.upload')) else: return HttpResponse('meow') def upload(request): if request.method == 'POST': blobs = get_uploads(request, field_name='file', populate_post=True) article = Article.objects.get(id=int(blobs[0].filename.split('.')[0])) article.media = blobs[0].filename article.parsed = True article.save() return HttpResponseRedirect(reverse('Articles.views.upload')) else: return HttpResponse('meow') # this serves the image def image(request): blob = BlobInfo.gql("WHERE filename='%s' LIMIT 1" % request.form.cleaned_data['id'])[0] return HttpResponse(BlobReader(blob.key()).read(), content_type=blob.content_type)

    Also you'll need this fabien.seisen/python/urllib2_file/

    更多推荐

    将视频上传到谷歌应用引擎blobstore

    本文发布于:2023-11-26 18:48:14,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:引擎   视频   blobstore

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!