@@ -167,6 +167,20 @@ def upload_local(uploaded_file, key, **kwargs):
167
167
return create_url (request .url , file_relative_path )
168
168
169
169
170
+ def create_url (request_url , file_relative_path ):
171
+ """Generates the URL of an uploaded file."""
172
+ url = urlparse (request_url )
173
+
174
+ # No need to specify scheme-corresponding port
175
+ port = url .port
176
+ if port and url .scheme == SCHEMES .get (url .port , None ):
177
+ port = None
178
+
179
+ return '{scheme}://{hostname}:{port}{file_relative_path}' .format (
180
+ scheme = url .scheme , hostname = url .hostname , port = port ,
181
+ file_relative_path = file_relative_path ).replace (':None' , '' )
182
+
183
+
170
184
def upload_to_aws (bucket_name , aws_region , aws_key , aws_secret , file , key , acl = 'public-read' ):
171
185
"""
172
186
Uploads to AWS at key
@@ -252,17 +266,3 @@ def generate_hash(key):
252
266
"""
253
267
phash = generate_password_hash (key , get_settings ()['secret' ])
254
268
return str (b64encode (phash ), 'utf-8' )[:10 ] # limit len to 10, is sufficient
255
-
256
-
257
- def create_url (request_url , file_relative_path ):
258
- """Generates the URL of an uploaded file."""
259
- url = urlparse (request_url )
260
-
261
- # No need to specify scheme-corresponding port
262
- port = url .port
263
- if port and url .scheme == SCHEMES .get (url .port , None ):
264
- port = None
265
-
266
- return '{scheme}://{hostname}:{port}{file_relative_path}' .format (
267
- scheme = url .scheme , hostname = url .hostname , port = port ,
268
- file_relative_path = file_relative_path ).replace (':None' , '' )
0 commit comments