делаю так:
url='http://sait.ru/file.mp4'
urllib.urlretrieve(url, “/home/users/django/1.mp4”)
файл сохраняется на сервак, вопрос: как сохранить не на серваке а на компе, чтобы вылезло как обычно окно сохранения?
def download_file(request): file_for_download = urllib2.urlopen('http://www.gravatar.com/avatar/d04439c330146886dad39b200c7f833d?default=retro&size=60') response = HttpResponse(mimetype='application/image') response['Content-Disposition'] = 'attachment; filename=avatar_of_error256.jpg' response.write(file_for_download.read()) return response
import requests r = requests.get(url) file_for_download = urllib2.urlopen(url) response = HttpResponse(mimetype=r.headers['content-type']) response['Connection'] = 'keep-alive' response['Content-Disposition'] = 'attachment; filename=test.mp4' tmp=file_for_download.read(1024) while(tmp!=''): response.write(tmp) tmp=file_for_download.read(1024) return response
def download_file(request): file_for_download = urllib2.urlopen('http://ru.fishki.net/picsw/032013/02/dengi/tn.jpg') response = StreamingHttpResponse(read_in_chunks(file_for_download), mimetype='application/image') response['Content-Disposition'] = 'attachment; filename=avatar_of_error256.jpg' return response def read_in_chunks(file_object): while True: data = file_object.read(1024) if not data: break yield data
<?php $url = "http://www.test.ru/большой_файл.mp4"; $headers = get_headers($url, TRUE); $name = basename($url); header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK'); header('Content-Length: ' . $headers['Content-Length']); header('Accept-Ranges: ' . ( isset($headers['Accept-Ranges']) ? $headers['Accept-Ranges'] : 'bytes' ) ); header('Date: ' . $headers['Date']); header('Content-Type: ' . $headers['Content-Type']); header('Last-Modifed: ' . $headers['Last-Modifed']); header('Connection: keep-alive'); header('Content-Disposition: attachment; filename="' . $name . '";'); @ob_end_clean(); $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOPROGRESS, false); curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'callback'); curl_setopt($ch, CURLOPT_BUFFERSIZE, 1024); curl_exec($ch); curl_close($ch); function callback($ch, $data) { echo $data; ob_flush(); return strlen($data); } ?>