将视频上传到谷歌应用引擎blobstore [英] Uploading a video to google app engine blobstore

查看:117
本文介绍了将视频上传到谷歌应用引擎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.org/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:

    1. User is served with a page containing a form with the following fields: Name, Description, File selector.
    2. 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 http://fabien.seisen.org/python/urllib2_file/

    这篇关于将视频上传到谷歌应用引擎blobstore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆