I'm getting this error every time I'm trying to upload video file, and I think the problem is come from the moviepy
library that I'm using to cut every video that are higher than 10 minute.
the error: AttributeError at /CreateVideo 'TemporaryUploadedFile' object has no attribute 'get'
views:
from moviepy.video.io.VideoFileClip import VideoFileClip
from django.core.exceptions import ValidationError
def create_video(request):
if request.method == 'POST':
title = request.POST['title']
video = request.FILES['video']
banner = request.FILES['banner']
video_file = video
video_clip = VideoFileClip(video_file.temporary_file_path())
duration = video_clip.duration
video_clip.close()
if duration > 600: # 10 minute in seconds
raise ValidationError('the video cannot be longer than 10 minute')
return video_file
new_video = Video.objects.create(
user=request.user,
title=title,
video=video,
banner=banner
)
new_video.save()
return redirect('Video')
return render(request, 'video/create_video.html')
models:
class Video(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
title = models.CharField(max_length=70)
video = models.FileField(upload_to='videos')
created_on = models.DateTimeField(auto_now_add=True)
banner = models.ImageField(upload_to='banner')
slug = models.SlugField(max_length=100, unique=True)