A web developer's blog. PHP, MySQL, CakePHP, Zend Framework, Wordpress, Code Igniter, Django, Python, CSS, Javascript, jQuery, Knockout.js, and other web development topics.

Monthly Archives: January 2011

Python: Saving a file from the URL by chunks

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)

Posted in General | Tagged | Leave a comment