I am using Celery to strip the audio from an uploaded video file. I want to save the audio file into my model where the video file is. So this is what I am trying:
# model
class Video(models.Model):
file = models.FileField(
validators=[
FileExtensionValidator(
allowed_extensions=["mp4", "mov", "flv", "mkv", "avi"]
)
]
)
processed_file = models.FileField(
validators=[FileExtensionValidator(allowed_extensions=["flac"])],
null=True,
blank=True,
)
# celery task
output_audio_file = str(settings.MEDIA_ROOT) + "/" + str(video_obj.pk) + ".flac"
ffmpeg.input(video_obj.file.path).output(
output_audio_file,
**{
"ac": 1,
"ar": 16000,
"format": "flac",
},
).run()
dj_file = File(open(output_audio_file))
video_obj.processed_file = dj_file
video_obj.save()
This raises the Detected path traversal attempt in '/app/proj/media/49.flac' exception. I also tried with the context manager, with the video_obj.processed_file.save() method. All of which raise TypeError, AttributeError, UnicodeDecodeError and so on. I feel like the answer could be so simple but I just couldn't find it.