S
S
Stanislav2019-10-09 23:13:45
Django
Stanislav, 2019-10-09 23:13:45

Post_save: how to get FileField url?

Greetings! I'm trying to create a preview image for a video file, but when I try to get the url of the saved video (instance.video.url), I get an error

sequence item 10: expected str instance, bytes found

def create_video_thumb(sender, instance, **kwargs):
    video_input_path = instance.video.url
    img_output_path = os.path.join(settings.MEDIA_ROOT, '/thumnail/image.jpg')
    subprocess.call(['ffmpeg', '-i', video_input_path, '-ss', '00:00:00.000', '-vframes', '1', img_output_path])

post_save.connect(create_video_thumb, sender=Detail)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2019-10-10
@Chebaa

Strange of course, but why not just cast the bytes to a string?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question