How to get the downloaded zip file in Django and save its contents (mp3 files)?

I am new to Django and I am trying to achieve what was mentioned ... but I was not able to get AudioField or MediaField in Django models, more or less likely ImageField.

Explaining what I want:

I want to provide the user with a form where he can fill in some information and can download a zip file containing mp3 files. Then, on the server, I want to get this zip file, unzip it, get the whole mp3 inside and get some information about those files (name, artist, duration, etc.) and store that in my model (music).

Is there some kind of tutorial explaining how to achieve this or some links explaining how to work with zip files and mp3 files?


source to share

2 answers

I think all you need is the following two links:

The Python standard library (both 2.xx and 3.xx) contains a module for working with zip files.


with ZipFile('') as zip_file:
    # get the list of files
    names = zip_file.namelist()
    # handle your files as you need. You can read the file with:
    with as f:
        music_file =
        # retrieve music_file metadata here


As for extracting metadata of mp3 files, there is a library:

Hope this helps you.



The field you are looking for is FileField , which is independent of the type of file it links to.

The Python standard library includes a package for working with Zip archives: zipfile .

You can use eyeD3 library to extract ID3 metadata from MP3 files.



All Articles