Code:
company = Company.objects.get(pk=pk)
if request.POST:
company_name = request.POST['company_name']
company_logo = request.FILES['company_logo']
fs = FileSystemStorage(location='/home/ubuntu/mywebsite/media/company/' + str(company.pk) + '/')
filename = fs.save(company_logo.name, company_logo)
uploaded_file_url = fs.url(filename)
fs.url returns: /media/thefilename.png which is wrong ... apparently the .url method doesn't take in to account what you've set your location attribute to?
How do I ensure that the correct path is being returned?
Ran into the same problem, so to complet what @alfonso.kim said, I had to specify both base_url and location. with your code it would be something like this
company = Company.objects.get(pk=pk)
if request.POST:
company_name = request.POST['company_name']
company_logo = request.FILES['company_logo']
dir_storage = '/home/ubuntu/mywebsite/media/company/' + str(company.pk) + '/'
fs = FileSystemStorage(location=dir_storage , base_url = dir_storage )
filename = fs.save(company_logo.name, company_logo)
uploaded_file_url = fs.url(filename)
Old thread, but hope it'll help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With