I'm creating a new class for file field to upload selected file on server through FTP. When in method
pre_save(), I'm trying to get file path this is raising below error:
The 'auth_img' attribute has no file associated with it.
Here is my class:
attr_class = FieldFile
descriptor_class = FileDescriptor
description = _("File")
def __init__(self, verbose_name=None, name=None, upload_to='', **kwargs):
self._unique_set_explicitly = 'unique' in kwargs
self._primary_key_set_explicitly = 'primary_key' in kwargs
if 'ext_whitelist' in kwargs:
ext_whitelist = kwargs.pop('ext_whitelist')
self.ext_whitelist = [i.lower() for i in ext_whitelist]
super(XFileField, self).__init__(verbose_name, name, upload_to, **kwargs)
def pre_save(self, model_instance, add):
file_ = super(XFileField, self).pre_save(model_instance, add)
if file_ is not None:
file_.save(file_.name, file_, save=True) # Raising Error Here
Here File will upload on server through FTP.
And also I don't want to save uploaded file, just wanting to use temporary uploaded local file and upload on FTP and the remove from local.