2👍
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
0👍
0👍
//settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
//end of settings.py
//this one is for save the image to preferred directory
logoRoot = os.path.join(settings.MEDIA_ROOT, 'images/')
//this is for accessing the image after you save it
logo_url = os.path.join(settings.MEDIA_URL, 'images/')
logoRoot=logoRoot.replace("\\","/")
fs = FileSystemStorage(location=logoRoot)
filename = fs.save(company_logo.name, company_logo)
//image url, don't use fs.url(filename) to get image url instead use code
below
uploaded_file_url = logo_url+filename
- [Answered ]-Unicode errror from Haystack indexing
- [Answered ]-When docker run, an error occurs. "ValueError: Unable to configure handler 'watchtower': You must specify a region."
- [Answered ]-How do you add a unique field (non empty) field to an existing model in Django?
Source:stackexchange.com