示例#1
0
文件: views.py 项目: pktck/bitparcel
def downloadFile(req, download_key, file_key, download_session_key, filename):
    bitparcel_download = BitparcelDownload(download_key, file_key, download_session_key, filename)

    response = HttpResponse(bitparcel_download.getChunkyKeyObj(), mimetype='application/octet-stream')
    response['Content-Disposition'] = 'attachment; filename="%s"' % bitparcel_download.row.filename
    response['Content-Length'] = bitparcel_download.row.size

    return response
示例#2
0
文件: views.py 项目: pktck/bitparcel
def download(req, download_key, filename):
    row = BitparcelDownload.getRow(download_key)

    url_filename = row.filename.replace(' ', '-')
    if (not filename) or (filename != url_filename):
        return HttpResponseRedirect('/%s/%s' % (download_key, url_filename))

    if row.downloads >= 5:
        return render_to_response('too_many_downloads.html', locals())

    download_session_key = DownloadSession.create()

    file_url = '/files/%s/%s/%s/%s' % (download_key, row.file_key, download_session_key, row.filename)

    return render_to_response('download.html', locals())