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.
The generic for of the command is:
youtube-upload --email=email --password=password --title=title --description=description --category=category video.avi
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.
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() ) )
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.
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_SIZEand
The
FILE_UPLOAD_HANDLERSby default are:And this give us 2 possibilities:
1. Remove the memory handler
Remove the
..MemoryFileUploadHandlerbut all your files will be saved in a temp file and this is not cool2. Modify the handlers on the fly
docs here
To get the file path you just need to do
video.temporary_file_path