Gets upload path in this format: {MODEL_NAME}/{SAFE_UPLOADED_FILENAME}{SUFFIX}.

    :param instance: Instance of model or model class.
    :param filename: Uploaded file name.
    :return: Target upload path.
13203
def auto_cleaned_path(instance, filename: str) -> str:
    
    stem, suffix = parse_filename(filename)
    base_dir = get_base_dir_from_object(instance)
    target_filename = get_safe_path_name(stem)

    return os.path.join(base_dir, "{target_filename}{suffix}".format(target_filename=target_filename,
                                                                     suffix=suffix))
911279
def example_filename(fn):
    
    fn = os.path.join(data_dir(), fn)
    if not os.path.exists(fn):
        raise ValueError("%s does not exist" % fn)
    return fn
60588
def get_hierarchy_uploader(root):
    
    # Workaround to avoid Django 1.7 makemigrations wierd behaviour:
    # More details: https://code.djangoproject.com/ticket/22436
    import sys
    if len(sys.argv) > 1 and sys.argv[1] in ('makemigrations', 'migrate'):
        # Hide ourselves from Django migrations
        return None

    from pymisc.utils.files import get_hierarchy_path
    def upload_to(instance, filename):
        file_name, file_ext = os.path.splitext(filename)
        return get_hierarchy_path(str(instance.id), file_ext, root, prefix_path_length=settings.PREFIX_PATH_LENGTH)
    return upload_to
205215
def get_relative_path_from_img_id(img_id, variant_label=None, ext=None, create_dirs=False):
    
    profile, base_name = img_id.split(':', 1)
    conf = get_profile_configs(profile)
    if not variant_label:
        status_suffix = dju_settings.DJU_IMG_UPLOAD_MAIN_SUFFIX
    else:
        status_suffix = dju_settings.DJU_IMG_UPLOAD_VARIANT_SUFFIX
    name, file_ext = os.path.splitext(base_name)
    prefix = ''
    if name.startswith(dju_settings.DJU_IMG_UPLOAD_TMP_PREFIX):
        name = name[len(dju_settings.DJU_IMG_UPLOAD_TMP_PREFIX):]
        prefix = dju_settings.DJU_IMG_UPLOAD_TMP_PREFIX
    name_parts = name.split('_', 2)
    name = '{name}{status_suffix}{hash}'.format(
        name=name,
        status_suffix=status_suffix,
        hash=get_hash('_'.join(name_parts[:2]), variant_label=variant_label)
    )
    if variant_label:
        name += '_' + variant_label
    if ext:
        file_ext = ext
    elif variant_label:
        for var_conf in conf['VARIANTS']:
            var_conf_label = var_conf['LABEL'] or get_variant_label(var_conf)
            if var_conf_label == variant_label:
                if var_conf['FORMAT']:
                    file_ext = var_conf['FORMAT'].lower()
                break
    if file_ext and not file_ext.startswith('.'):
        file_ext = '.' + file_ext
    relative_path = os.path.join(
        dju_settings.DJU_IMG_UPLOAD_SUBDIR,
        conf['PATH'],
        name_parts[0][-2:],
        (prefix + name + file_ext)
    ).replace('\\', '/')
    if create_dirs:
        path = media_path(relative_path)
        make_dirs_for_file_path(path, mode=dju_settings.DJU_IMG_CHMOD_DIR)
    return relative_path
684309
def get_image_file_path(instance, filename):
    """"""
    ext = filename.split('.')[-1]
    filename = '%s.%s' % (uuid.uuid4(), ext)
    return os.path.join(
        'user_media', str(instance.user.pk), 'images', filename)
229104
def open_instance_resource(self, path: FilePath, mode: str='rb') -> IO[AnyStr]:
        
        return open(self.instance_path / file_path_to_path(path), mode)
608779
def get_filepath(self, filename):
        
        return os.path.join(self.parent_folder, '{},{},{}'.format(self.tile_name, self.date, self.aws_index),
                            self.add_file_extension(filename)).replace(':', '.')
785661
def file_path(self) -> str:
        
        user_dir = self.__get_user_path()
        file_path = path.abspath(path.join(user_dir, self.FILENAME))
        return file_path
887189
def set_img_path(instance, filename):
    
    upload_path = '/'.join(
        ['img', instance._meta.app_label, str(now.year), str(now.month), filename]
    )
    return upload_path
1234651
def upload_check(self, filename=None, folder_key=None, filedrop_key=None,
                     size=None, hash_=None, path=None, resumable=None):
        
        return self.request('upload/check', QueryParams({
            'filename': filename,
            'folder_key': folder_key,
            'filedrop_key': filedrop_key,
            'size': size,
            'hash': hash_,
            'path': path,
            'resumable': resumable
        }))
426048
def _get_instance_path(self, name):
        ""
        fname = self.pattern.format(**{'name': name})
        logger.debug(f'path {self.create_path}: {self.create_path.exists()}')
        self._create_path_dir()
        return Path(self.create_path, fname)
900260
def Upload(cls, filename):
        
        raise Exception("to do")
    
        TOOLS_PATH = ""
        RESOURCE_PATH = ""
        tool_4path = os.path.join(TOOLS_PATH, "upload.exe")        
        file_4path = os.path.join(RESOURCE_PATH, filename)
        #file_4path.decode('utf-8').encode('gbk')
        
        if os.path.isfile(file_4path):
            cls.Click()
            os.system(tool_4path + ' ' + file_4path)
        else:
            raise Exception('%s is not exists' % file_4path)
110506
def safe_filename(file_name, sep='_', default=None, extension=None):
    """"""
    if file_name is None:
        return decode_path(default)

    file_name = decode_path(file_name)
    file_name = os.path.basename(file_name)
    file_name, _extension = os.path.splitext(file_name)
    file_name = _safe_name(file_name, sep=sep)
    if file_name is None:
        return decode_path(default)
    file_name = file_name[:MAX_LENGTH]
    extension = _safe_name(extension or _extension, sep=sep)
    if extension is not None:
        file_name = '.'.join((file_name, extension))
        file_name = file_name[:MAX_LENGTH]
    return file_name
543767
def get_path_to_file_from_url(cls, url):
        
        file_name = urlparse(url).path.split('/')[-1]
        return os.path.join(PYUNIPROT_DATA_DIR, file_name)
797527
def _url(self, url, file_upload=False):
        

        host = self.api_url
        if file_upload:
            host = self.uploads_api_url

        protocol = 'https' if self.https else 'http'
        if url.endswith('/'):
            url = url[:-1]
        return '{0}://{1}/{2}'.format(
            protocol,
            host,
            url
        )
932530
def locate_file name
      Settings.instance.target_dir.each do |dir|
        Dir.chdir File.expand_path(dir) do
          return File.expand_path(name) if File.exists? name
        end
      end
      raise TargetLoadError.new("Couldn't find file #{name}")
      nil
    end
502512
def get_upload_key(self):
        

        if not hasattr(self, '_upload_key'):
            self._upload_key = self.get_storage().bucket.get_key(
                self.cleaned_data['key_name'])
        return self._upload_key