View

descargar images en disco

  1. def downloadImage(self):
  2.     img_url = ‘http://img1cdn.adoosimg.com/b195d543e38e349deac032b41be043c7-1-5.jpg’
  3.     imgName = ‘b195d543e38e349deac032b41be043c7-1-5.jpg’
  4.     imgN = “peque_%s”%imgName.replace(‘5.’,‘7.’) if imgName[-5:]==‘5.jpg’ else imgName
  5.     file_path = “%s/adoos/%s” % (settings.UPLOAD_PATH, imgN)
  6.     downloaded_image = file(file_path, “wb”)
  7.     image_on_web = urllib.urlopen(img_url)
  8.     while True:
  9.         buf = image_on_web.read(65536)
  10.         if len(buf) == 0:
  11.             break
  12.         downloaded_image.write(buf)
  13.     downloaded_image.close()
  14.     image_on_web.close()
  15.     return  file_path

Note

descragar y cambiar de nombre al archivo

You may also like