2

I have two application server 10.1.xx.xx and 10.1.xx.yy and middle of both I have load balancer 10.5.aa.bb and I have deployed my Django application in both the servers successfully and able to access the application too.

There is a shared folder in between both the servers where I have to upload the images so that both servers have access of all the images, but I don't have any idea, how should I do it? up-till now I just upload the images in project folder. I googled a lot I just got this blog, http://www.bogotobogo.com/python/Django/Python_Django_Image_Files_Uploading_On_Shared_Host_Example.php

but It is also not working.

I tried with following setting but it is uploading file in project directory.

settings.py

MEDIA_URL = '/home/bynry-01/www/media/'
MEDIA_ROOT='http://192.168.1.109:3333/www/media/'

model.py

class Document(models.Model):
    description = models.CharField(max_length=255, blank=True)
    document = models.FileField(upload_to='documents/')
    uploaded_at = models.DateTimeField(auto_now_add=True)

views.py

document=Document()
document.document = request.FILES['imgfile']
document.save()
Vikram Singh Chandel
  • 1,290
  • 2
  • 17
  • 36
  • "is not working" is possibly the most useless description of a problem. How are you handling your uploads ? with `models.FileField`s ? Manually ? If yes how ? Where does your `settings.MEDIA_ROOT|` points to ? and, most important, __what happens exactly when you upload a file__ ? – bruno desthuilliers Dec 07 '16 at 11:16
  • FWIW for the most common use case (`models.FileField` + `forms.ModelForm`), all you have to do is to 1/ make your `settings.MEDIA_ROOT` point to somewhere on the shared folder, then 2/ make sure your front server can serve files from your `settings.MEDIA_ROOT`. – bruno desthuilliers Dec 07 '16 at 11:18
  • @brunodesthuilliers I didn't do file upload up-till now because I don't know how should I upload file in shared host/folder. – Vikram Singh Chandel Dec 07 '16 at 11:21
  • From the system (hence from your django app) POV, the fact that it's a shared folder is totally irrelevant - it's a folder on the filesystem, period. Works just like any other folder on your filesystem. Except for a correct system config (which is your sysadmin's job) and correct production django settings for your `MEDIA_ROOT` and `MEDIA_URL`, you don't have anything special to do. – bruno desthuilliers Dec 07 '16 at 11:30
  • Oh and forget about this bogotbogo example - this is useless crap. There's no shortage of correct django examples and tutorials - starting with the official documentation, so don't waste your time with the useless ones. – bruno desthuilliers Dec 07 '16 at 11:32
  • @brunodesthuilliers I tried to upload files out of the project directory by setting the `MEDIA_ROOT` and `MEDIA_URL` but it created the folder with name that I have mentioned in `MEDIA_ROOT`, in project root directory and uploaded files. – Vikram Singh Chandel Dec 07 '16 at 12:08
  • Then either you've edited the wrong settings (if you have distinct settings for each environment) or your MEDIA_ROOT settings is wrong. – bruno desthuilliers Dec 07 '16 at 12:21

0 Answers0