How to save file uploaded into folder located out of Django project folder ?

Hi

I would like to save the uploaded file through models but save the physical file out of Django project folder such as shared-folder (\127.0.0.1\incident_docs).

How to implement this scenario?

Django project folder = C:\Django-WebApp\SMartApp
Shared-Folder = D:\incident_docs (shared path)

I have studied as the following links.
https://docs.djangoproject.com/en/3.1/ref/models/fields/#filefield

https://docs.djangoproject.com/en/3.1/topics/files/

I try as code below, it occurred error.

Message=The joined path (\127.0.0.1\incident_docs\incident_29\search-poor.png) is located outside of the base path component (C:\Django-WebApp\SMartApp)

  • Source=C:\Django-WebApp\SMartApp\app\decorators.py*
  • StackTrace:*
  • File “C:\Django-WebApp\SMartApp\app\decorators.py”, line 22, in wrapper_func*
  • return view_func(request, *args, *kwargs)
private_storage = FileSystemStorage(location=r'\\127.0.0.1\incident_docs')
def incident_directory_path(instance, filename):
    # file will be uploaded to MEDIA_ROOT/incident_<id>/<filename>
    incidentID=instance.incident_ref.id
    incident_filename= filename
 
    x_path = '{0}\{1}{2}\{3}'.format(settings.PRIVATE_STORAGE_ROOT,settings.INCIDENT_PREFIX_DOC, incidentID, incident_filename)
    return (x_path)

class Incident_File(models.Model):

    incident_file = models.FileField('Upload File',upload_to=incident_directory_path, blank=True, max_length=254)

    incident_ref = models.ForeignKey(Incident, on_delete=models.CASCADE, related_name='files',blank=True)

Thank you.
Pongthorn

Review the FileField.upload_to docs.
Briefly, the path must be specified Unix-style, and would not include the host.
Also, you want to make sure your MEDIA_ROOT setting is correct, and that the path you’re providing is either based from root or relative to MEDIA_ROOT.

you want to make sure your MEDIA_ROOT setting is correct, and that the path you’re providing is either based from root or relative to MEDIA_ROOT.

I already understood.
Thank you.