How to find file extension in case of file list?

How can I find the file list extension. I am currently using os.path.splitext, which does not work. Please suggest any other method in case of file list.

My code is here:

files = request.FILES.getlist('media')
            for f in files:
                p = os.path.splitext(f)[1]
                print p

Error displayed here 'InMemoryUploadedFile' object has no attribute 'rfind'

Thanks in advance

+4
source share
1 answer

From the error and the code, it seems that you are using Django, so you should get the name of the object and not the object itself as:

 p = os.path.splitext(f.name)[1]

which will give the file name, not the file.

+2
source

Source: https://habr.com/ru/post/1674715/


All Articles