[英]Upload movie file in Dailymotion through Django
I am developping a webapplication for a movie challenge organised by an association. 我正在为协会组织的电影挑战开发Web应用程序。 My association and I want to directly upload submitted movies to the Dailymotion account of the association.
我和我的协会想直接将提交的电影上载到协会的Dailymotion帐户。
I already done tests localy to understand how to upload movie in Dailymotion and it works fine with a simple Python script, the Python SDK provided by Dailymotion, and using the direct path of the movie stored in my hard drive. 我已经在本地进行了测试,以了解如何在Dailymotion中上载电影,它可以与简单的Python脚本,Dailymotion提供的Python SDK配合使用,并使用存储在硬盘中的电影的直接路径来正常工作。 It works like a charm so I tried to implement it in the Django application I am developping.
它的工作原理就像一种魅力,因此我尝试在我正在开发的Django应用程序中实现它。
I don't understand what happens, but if I try through the form, it returns me this error: 我不知道会发生什么,但是如果我尝试填写表格,它将返回此错误:
TypeError at /a/bioinfuse/submit_movie/15
expected string or Unicode object, NoneType found
Request Method: POST
Request URL: http://127.0.0.1:8000/a/bioinfuse/submit_movie/15
Django Version: 1.9.5
Exception Type: TypeError
Exception Value:
expected string or Unicode object, NoneType found
Exception Location: /home/nolwenn/.virtualenvs/jebif-django/local/lib/python2.7/site-packages/pp.py in submit, line 461
Python Executable: /home/nolwenn/.virtualenvs/jebif-django/bin/python
Python Version: 2.7.6
Python Path:
['/home/nolwenn/programmation/jebif',
'/home/nolwenn/.virtualenvs/jebif-django/lib/python2.7',
'/home/nolwenn/.virtualenvs/jebif-django/lib/python2.7/plat-x86_64-linux-gnu',
'/home/nolwenn/.virtualenvs/jebif-django/lib/python2.7/lib-tk',
'/home/nolwenn/.virtualenvs/jebif-django/lib/python2.7/lib-old',
'/home/nolwenn/.virtualenvs/jebif-django/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/nolwenn/.virtualenvs/jebif-django/local/lib/python2.7/site-packages',
'/home/nolwenn/.virtualenvs/jebif-django/lib/python2.7/site-packages']
Here is the submit_video view: 这是submit_video视图:
def submit_movie(request, member):
def submit_movie(d, file, data, m_id):
q_movie = Movie.objects.get(id=m_id)
url = d.upload(file)
movie = d.post('/me/videos',
{'url': url, 'title': data['title'],
'published': 'true', 'channel': 'tech',
'private': 'true',
'description': data['description']})
url = d.get('/video/'+movie,
{'fields': 'embed_url', 'id': id_movie})['embed_url']
q_movie.url = url
q_movie.save()
context = base(request)
role = Member.objects.get(user=member).role
member = Member.objects.get(user=member)
challenge = Challenge.objects.filter(is_open=True).order_by('stop_date')[0]
if request.method == 'GET':
submit_movie_form = SubmitMovieForm({'submit_date': now()})
else:
submit_movie_form = SubmitMovieForm(request.POST, request.FILES)
if submit_movie_form.is_valid():
title = submit_movie_form.cleaned_data['title']
description = submit_movie_form.cleaned_data['description']
submit_date = submit_movie_form.cleaned_data['submit_date']
file_movie = request.FILES['file_movie']
associated_key = AssociatedKey.objects.get(associated_key=member.associated_key)
register_movie = Movie(challenge=challenge,
associated_key=associated_key,
title=title,
description=description,
submit_date=submit_date)
register_movie.save()
m_id = register_movie.id
d = dailymotion.Dailymotion()
d.set_grant_type('password', api_key=API_KEY,
api_secret=API_SECRET, scope=['manage_videos'],
info={'username': USERNAME, 'password': PASSWORD})
data = {'title': title, 'description': description}
job = pp.Server()
job.submit(submit_movie, (d, file_movie, data, m_id))
return HttpResponseRedirect(reverse('bioinfuse:index'))
context['submit_movie_form'] = submit_movie_form
context['role'] = role
return render(request, "submit_movie.html", context)
The SubmitMovieForm form: SubmitMovieForm表单:
class SubmitMovieForm(forms.ModelForm):
file_movie = forms.FileField(label="Votre vidéo")
class Meta:
model = Movie
exclude = ('challenge', 'associated_key', 'movie_url', 'published')
And the template form used: 和使用的模板形式:
<form action="{% url 'bioinfuse:submit_movie' user.id %}" method="post" enctype="multipart/form-data">{% csrf_token %}
<fieldset>
{{ submit_movie_form.as_p }}
<input type="submit" value="Mettre à jour">
</fieldset>
</form>
I wonder if Django wants that I first upload the movie in the server, but I wish to directly upload the movie file in Dailymotion, without having to store the file in the server. 我想知道Django是否希望我首先在服务器中上传电影,但是我希望直接在Dailymotion中上传电影文件,而不必将文件存储在服务器中。
Do you know how I can manage to directly upload the movie in Dailymotion without creating a temporary file in our server? 您知道我可以如何直接在Dailymotion中上载电影而无需在我们的服务器中创建临时文件吗? If it is possible, of course.
当然可以。
Want to see more code? 想查看更多代码? Go on this GitHub repository , the application name is bioinfuse.
转到此GitHub存储库 ,应用程序名称为bioinfuse。
TL;DR: How to upload a movie in Dailymotion, through Django, without storing it on the server of the webapplication? TL; DR:如何通过Django在Dailymotion中上传电影,而不将其存储在Web应用程序的服务器上?
Thanks in advance! 提前致谢!
No it is not possible. 不,这是不可能的。 The file need to be temporarily inside your server because the request go through your server.
该文件需要临时放在服务器中,因为请求通过服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.