Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. def download_remote_file(file_url, file_path=None):
  2. if file_path == None:
  3. file_path = BASE_ROOT + '/templates/static/assets/uploads/'
  4.  
  5. response = requests.get(file_url, stream=True)
  6.  
  7.  
  8. file_extension = file_url.split('.')[-1]
  9.  
  10. random_file_name = get_random_token(file_url)
  11.  
  12. full_file_name = random_file_name + "." + file_extension
  13.  
  14. with open(file_path + full_file_name, 'wb') as out_file:
  15. shutil.copyfileobj(response.raw, out_file)
  16.  
  17. del response
  18.  
  19. return full_file_name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement