在临时存储器中访问用户上传的视频时出现问题 [英] Problem accessing user uploaded video in temporary memory

查看:73
本文介绍了在临时存储器中访问用户上传的视频时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用html输入类型文件和python模块youtube-upload将用户上传的视频提交给youtube。提交表单后,其处理方式如下:

I'm trying to submit a user uploaded video to youtube using an html input type file and the python module youtube-upload. When the form is submitted it is handled like so:

if request.method == 'POST':
    video = request.FILES['file']

    v=str(video)

    command = 'youtube-upload --email=email@gmail.com --password=password --title=title --description=description --category=Sports ' + v

    r = subprocess.Popen(command,   stdout=subprocess.PIPE)
    v = r.stdout.read()

所以我认为问题是我需要为视频提供更完整的路径。在这种情况下,访问临时存储器中视频的路径是什么。

So I would assume the problem is that I need to provide a more complete path for the video. If this is the case, what is the path to access the video in temporary memory.

该命令的通用含义是:
youtube-upload --email = email --password = password --title = title --description = description --category = category video.avi

The generic for of the command is: youtube-upload --email=email --password=password --title=title --description=description --category=category video.avi

或者,我在此处,但如果有人能提供使用api在python中执行此操作的更完整说明,那将是惊人的。不幸的是,该站点上的指南仅关注xml。

Alternatively, I've looked at the youtube api specifically here but if anyone could provide a more complete explanation of how to do this in python using the api that would be amazing. Unfortunately, the guide on the site just focuses on the xml.

根据sacabuche的评论进行编辑:

EDIT FOLLOWING sacabuche's COMMENT:

所以我的观点现在大致是:

so my view is now roughly:

def upload_video(request):
     if request.method == 'POST':
         video = request.FILE['file']
         v = video.temporary_file_path
         command = 'youtube-upload --email=email@gmail.com --password=password --title=title --description=description --category=Sports ' + v   

         r=subprocess.Popen(command, stdout=subprocess.PIPE)

         vid = r.stdout.read()
     else:
         form = VideoForm()
         request.upload_handlers.pop(0)
     return render_to_response('create_check.html', RequestContext(request, locals() ) )

但是 v = video.temporary_file_path 绘制错误'InMemoryUploadedFile'对象没有错误属性 temporary_file_path 。因此视频仍在临时存储器中,我不知道应该调用哪个对象 temporary_file_path 或如何获取该对象。

but v=video.temporary_file_path draws the error 'InMemoryUploadedFile' object has no attribute 'temporary_file_path'. So video is still in temporary memory and I don't know what object temporary_file_path is suppose to be called on or how to get said object.

推荐答案

事实上django将文件保存在内存中,但是大文件保存在路径中。

大文件的大小应大于可以使用 FILE_UPLOAD_MAX_MEMORY_SIZE



在设置中定义 FILE_UPLOAD_HANDLERS 默认为:

In fact django save the files on memory, but large files are saved in a path.
The size of "large file" can be defined in settings using FILE_UPLOAD_MAX_MEMORY_SIZE
and
The FILE_UPLOAD_HANDLERS by default are:

("django.core.files.uploadhandler.MemoryFileUploadHandler",
 "django.core.files.uploadhandler.TemporaryFileUploadHandler",)

这给了我们2种可能性:

And this give us 2 possibilities:

删除 .. MemoryFileUploadHandler ,但是所有文件都将保存在临时文件中,这并不酷

Remove the ..MemoryFileUploadHandler but all your files will be saved in a temp file and this is not cool

文档在这里

#views.py

def video_upload(request):
    # this removes the first handler (MemoryFile....)
    request.upload_handlers.pop(0)
    return _video_upload(request)

def _video_upload(request):
    ....

要获取文件路径,您只需需要做 video.temporary_file_path

To get the file path you just need to do video.temporary_file_path

这篇关于在临时存储器中访问用户上传的视频时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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