Example #1
0
def download_package(request,file_id):
    try:
        file=FileInfo.objects.get(int(file_id))
        contents=FileInfoService.download_file(file_id)
        def file_iterator(chunk_size=1024*50):
            while True:
                c = contents.read(chunk_size)
                if c:
                    yield c
                else:
                    break
        result=StreamingHttpResponse(file_iterator(), content_type='application/octet-stream')
        display_file_name=str(file.FileName.encode("utf-8")).replace("'","")
        result['Content-Disposition'] = 'attachment;filename="'+display_file_name+'"'
    except  Exception as ex:
        result=HttpResponse(str(ex))
        SimpleLogger.exception(ex)
    return result

    
    
    


    
    def get_file_stream(self, file_id):
        file = FileInfo.objects.get(int(file_id))
        contents = FileInfoService.download_file(file_id)

        def file_iterator(chunk_size=1024 * 50):
            while True:
                c = contents.read(chunk_size)
                if c:
                    yield c
                else:
                    break

        result = StreamingHttpResponse(file_iterator(),
                                       content_type='application/octet-stream')
        result[
            'Content-Disposition'] = 'attachment;filename="' + file.FileName + '"'
        return result