For example, when you want to save an image from a URL.
https://github.com/images/modules/header/logov3-hover.png |
f = urllib.urlopen(request.POST['url']) p = os.path.join(settings.UPLOAD_DIRECTORY, "saved_file.jpg") filesize = 0 with open(p,'wb') as output: while True: buf = f.read(65536) filesize += len(buf) if not buf: break output.write(buf) |