def get(self, cluster, environ, topology, container): ''' :param cluster: :param environ: :param topology: :param container: :return: ''' offset = self.get_argument("offset") length = self.get_argument("length") path = self.get_argument("path") data = yield access.get_container_file_data(cluster, environ, topology, container, path, offset, length) self.write(data) self.finish()
def get(self, cluster, environ, topology, container): ''' :param cluster: :param environ: :param topology: :param container: :return: ''' # If the file is large, we want to abandon downloading # if user cancels the requests. # pylint: disable=attribute-defined-outside-init self.connection_closed = False path = self.get_argument("path") filename = path.split("/")[-1] self.set_header("Content-Disposition", "attachment; filename=%s" % filename) # Download the files in chunks. We are downloading from Tracker, # which in turns downloads from heron-shell. This much indirection # means that if we use static file downloading, the whole files would # be cached in memory before it can be sent downstream. Hence, we reuse # the file data API to read in chunks until the EOF, or until the download # is cancelled by user. # 4 MB gives good enough chunk size giving good speed for small files. # If files are large, a single threaded download may not be enough. length = 4 * 1024 * 1024 offset = 0 while True: response = yield access.get_container_file_data( cluster, environ, topology, container, path, offset, length) if self.connection_closed or 'data' not in response or len( response['data']) < length: break offset += length self.write(response['data']) self.flush() self.write(response['data']) self.finish()
def get(self, cluster, environ, topology, container): ''' :param cluster: :param environ: :param topology: :param container: :return: ''' # If the file is large, we want to abandon downloading # if user cancels the requests. # pylint: disable=attribute-defined-outside-init self.connection_closed = False path = self.get_argument("path") filename = path.split("/")[-1] self.set_header("Content-Disposition", "attachment; filename=%s" % filename) # Download the files in chunks. We are downloading from Tracker, # which in turns downloads from heron-shell. This much indirection # means that if we use static file downloading, the whole files would # be cached in memory before it can be sent downstream. Hence, we reuse # the file data API to read in chunks until the EOF, or until the download # is cancelled by user. # 4 MB gives good enough chunk size giving good speed for small files. # If files are large, a single threaded download may not be enough. length = 4 * 1024 * 1024 offset = 0 while True: response = yield access.get_container_file_data(cluster, environ, topology, container, path, offset, length) if self.connection_closed or 'data' not in response or len(response['data']) < length: break offset += length self.write(response['data']) self.flush() self.write(response['data']) self.finish()