django request absolute file path

898 Views Asked by At

using django requests, I am trying to get the absolute file path of original, uploaded file. The reason is I want to modify the original file so just the filename or some "media root" location just isn't enough.

I tried doing something like

request.FILES['file'].name

but that just gives me the name, not a path (neither absolute nor relative). google didn't really help, filenames are common, but path seems to be a special case. I hope it's even possible XP.

Thx in advance!

1

There are 1 best solutions below

6
On

Try this.

myfile = request.FILES['filename']

fs = FileSystemStorage()

filename = fs.save(myfile.name, myfile)

uploaded_file_url = fs.url(filename)

print(uploaded_file_url)

Also make sure you add the 'django.core.files.storage.FileSystemStorage' under Middleware_classes in settings.py file