Python django.utils.encoding.filepath_to_uri() Examples
The following are 14
code examples of django.utils.encoding.filepath_to_uri().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.utils.encoding
, or try the search function
.
Example #1
Source File: s3boto3.py From django-storages with BSD 3-Clause "New" or "Revised" License | 6 votes |
def url(self, name, parameters=None, expire=None, http_method=None): # Preserve the trailing slash after normalizing the path. name = self._normalize_name(self._clean_name(name)) if expire is None: expire = self.querystring_expire if self.custom_domain: url = "{}//{}/{}".format( self.url_protocol, self.custom_domain, filepath_to_uri(name)) if self.querystring_auth and self.cloudfront_signer: expiration = datetime.utcnow() + timedelta(seconds=expire) return self.cloudfront_signer.generate_presigned_url(url, date_less_than=expiration) return url params = parameters.copy() if parameters else {} params['Bucket'] = self.bucket.name params['Key'] = name url = self.bucket.meta.client.generate_presigned_url('get_object', Params=params, ExpiresIn=expire, HttpMethod=http_method) if self.querystring_auth: return url return self._strip_signing_parameters(url)
Example #2
Source File: azure_storage.py From django-storages with BSD 3-Clause "New" or "Revised" License | 6 votes |
def url(self, name, expire=None): name = self._get_valid_path(name) if expire is None: expire = self.expiration_secs make_blob_url_kwargs = {} if expire: sas_token = self.custom_service.generate_blob_shared_access_signature( self.azure_container, name, permission=BlobPermissions.READ, expiry=self._expire_at(expire)) make_blob_url_kwargs['sas_token'] = sas_token return self.custom_service.make_blob_url( container_name=self.azure_container, blob_name=filepath_to_uri(name), protocol=self.azure_protocol, **make_blob_url_kwargs)
Example #3
Source File: storage.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def url(self, name): if self.base_url is None: raise ValueError("This file is not accessible via a URL.") gridfs, filename = self._get_gridfs(name) try: file_oid = gridfs.get_last_version(filename=name).__getattr__('_id') except NoFile: # In case not found by filename try: # Check is a valid ObjectId file_oid = ObjectId(name) except (InvalidId, TypeError, ValueError): return None # Check if exist a file with that ObjectId if not gridfs.exists(file_oid): return None return urljoin(self.base_url, filepath_to_uri(str(file_oid)))
Example #4
Source File: storage.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def url(self, name): if self.base_url is None: raise ValueError("This file is not accessible via a URL.") return urljoin(self.base_url, filepath_to_uri(name))
Example #5
Source File: backends.py From django-qiniu-storage with MIT License | 5 votes |
def url(self, name): name = self._normalize_name(self._clean_name(name)) name = filepath_to_uri(name) protocol = u'https://' if self.secure_url else u'http://' return urljoin(protocol + self.bucket_domain, name)
Example #6
Source File: storage.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def url(self, name): if self.base_url is None: raise ValueError("This file is not accessible via a URL.") return urljoin(self.base_url, filepath_to_uri(name))
Example #7
Source File: fields.py From ctf-gameserver with ISC License | 5 votes |
def get_thumbnail_url(self): """ Returns the (absolute) URL for the image's thumbnail version. """ return urljoin(settings.MEDIA_URL, filepath_to_uri(self.get_thumbnail_path()))
Example #8
Source File: fields.py From ctf-gameserver with ISC License | 5 votes |
def get_thumbnail_url(self): """ Returns the (absolute) URL for the image's thumbnail version. """ return urljoin(settings.MEDIA_URL, filepath_to_uri(self.get_thumbnail_path()))
Example #9
Source File: fields.py From ctf-gameserver with ISC License | 5 votes |
def get_thumbnail_url(self): """ Returns the (absolute) URL for the image's thumbnail version. """ return urljoin(settings.MEDIA_URL, filepath_to_uri(self.get_thumbnail_path()))
Example #10
Source File: fields.py From ctf-gameserver with ISC License | 5 votes |
def get_thumbnail_url(self): """ Returns the (absolute) URL for the image's thumbnail version. """ return urljoin(settings.MEDIA_URL, filepath_to_uri(self.get_thumbnail_path()))
Example #11
Source File: fields.py From ctf-gameserver with ISC License | 5 votes |
def get_thumbnail_url(self): """ Returns the (absolute) URL for the image's thumbnail version. """ return urljoin(settings.MEDIA_URL, filepath_to_uri(self.get_thumbnail_path()))
Example #12
Source File: storage_backends.py From hypha with BSD 3-Clause "New" or "Revised" License | 5 votes |
def url(self, name, parameters=None, expire=None): url = super().url(name, parameters, expire) if hasattr(settings, 'AWS_PRIVATE_CUSTOM_DOMAIN'): # Django storage doesn't handle custom domains with auth strings custom_domain = settings.AWS_PRIVATE_CUSTOM_DOMAIN parts = list(parse.urlsplit(url)) parts[1:3] = custom_domain, filepath_to_uri(name) return parse.urlunsplit(parts) return url
Example #13
Source File: storage.py From wagtailvideos with BSD 3-Clause "New" or "Revised" License | 5 votes |
def url(self, name): if self.base_url is None: raise ValueError("This file is not accessible via a URL.") url = filepath_to_uri(name) if url is not None: url = url.lstrip('/') return urljoin(self.base_url, url)
Example #14
Source File: backends.py From django-aliyun-oss2-storage with MIT License | 5 votes |
def url(self, name): name = self._normalize_name(self._clean_name(name)) # name = filepath_to_uri(name) # 这段会导致二次encode name = name.encode('utf8') # 做这个转化,是因为下面的_make_url会用urllib.quote转码,转码不支持unicode,会报错,在python2环境下。 return self.bucket._make_url(self.bucket_name, name)