if user: | |
if profile_pic_upload != 'false': | |
fs = FileSystemStorage() | |
profile_pic = compress_image(profile_pic_upload) | |
filename = fs.save(profile_pic_upload.name, profile_pic) | |
uploaded_file_url = fs.url(filename) | |
uploaded_file_url = uploaded_file_url.split("/") | |
original_url= uploaded_file_url[-1] | |
user_profile.profile_pic = original_url Here fs is the object of the FileSystemStorege() class compress_image() is my custom function no need to add that, you can directly pass the image object that you are getting from request. then the origina_url will go to DB user_profile.profile_pic = original_url <where user_profile is table and profile_pic is field and original_url is the URL that we get from FileSystemStorage()> also, it will add a randomly generated value at the end of the file that will be very useful if you have 2 images with the same name NOTE make sure that you have a media folder added to you your settings.py file or you can pass the path to where to save the image like this fs = FileSystemStorage(location='media/rent_pictures/') Hope this helps another thing is that image is also a file and treated the same way in the backend regards, |
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WabzCG%2B4ARdyzdn-3DCckud%3D871RtOSxqRiRMLo6zbQuQ%40mail.gmail.com.
Robert Rajendra
Associate Network/Server Support Engineer
IT Hands
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABbC_KHUHtuJRsGUFNqf%2BXK5CZy9oewdueTdjZ6r7A%3DQTTNDQg%40mail.gmail.com.