-
def downloadImage(self):
-
img_url = ‘http://img1cdn.adoosimg.com/b195d543e38e349deac032b41be043c7-1-5.jpg’
-
imgName = ‘b195d543e38e349deac032b41be043c7-1-5.jpg’
-
imgN = “peque_%s”%imgName.replace(‘5.’,‘7.’) if imgName[-5:]==‘5.jpg’ else imgName
-
file_path = “%s/adoos/%s” % (settings.UPLOAD_PATH, imgN)
-
downloaded_image = file(file_path, “wb”)
-
image_on_web = urllib.urlopen(img_url)
-
while True:
-
buf = image_on_web.read(65536)
-
if len(buf) == 0:
-
break
-
downloaded_image.write(buf)
-
downloaded_image.close()
-
image_on_web.close()
-
return file_path
Note
descragar y cambiar de nombre al archivo