Reputation: 79
I am developping a webapplication for a movie challenge organised by an association. My association and I want to directly upload submitted movies to the Dailymotion account of the association.
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. It works like a charm so I tried to implement it in the Django application I am developping.
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:
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:
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.
Do you know how I can manage to directly upload the movie in Dailymotion without creating a temporary file in our server? If it is possible, of course.
Want to see more code? Go on this GitHub repository, the application name is bioinfuse.
TL;DR: How to upload a movie in Dailymotion, through Django, without storing it on the server of the webapplication?
Thanks in advance!
Upvotes: 0
Views: 437
Reputation: 2816
No it is not possible. The file need to be temporarily inside your server because the request go through your server.
Upvotes: 1