async def iter_data(self) -> AsyncIterator[bytes]: file = self.field.get(self.field.context or self.context) if not getattr(file, "_blob", None): raise FileNotFoundException() blob = file._blob bfile = blob.open() async for chunk in bfile.iter_async_read(): yield chunk
async def iter_data(self, uri=None): if uri is None: file = self.field.get(self.field.context or self.context) uri = file.uri if uri not in _tmp_files: raise FileNotFoundException(uri) with open(_tmp_files[uri], "rb") as fi: chunk = fi.read(1024) while chunk: yield chunk chunk = fi.read(1024)
async def iter_data(self, uri=None, headers=None): if uri is None: file = self.field.get(self.field.context or self.context) if not _is_uploaded_file(file): raise FileNotFoundException( "Trying to iterate data with no file") else: uri = file.uri if headers is None: headers = {} util = get_utility(IGCloudBlobStore) url = "{}/{}/o/{}".format(OBJECT_BASE_URL, await util.get_bucket_name(), quote_plus(uri)) headers["AUTHORIZATION"] = "Bearer {}".format(await util.get_access_token()) async with util.session.get(url, headers=headers, params={"alt": "media"}, timeout=-1) as api_resp: if api_resp.status not in (200, 206): text = await api_resp.text() if api_resp.status == 404: raise HTTPNotFound( content={ "reason": "Google cloud file not found", "response": text, }) elif api_resp.status == 401: log.warning( f"Invalid google cloud credentials error: {text}") raise HTTPNotFound( content={ "reason": "Google cloud invalid credentials", "response": text, }) raise GoogleCloudException(f"{api_resp.status}: {text}") while True: chunk = await api_resp.content.read(1024 * 1024) if len(chunk) > 0: yield chunk else: break
async def iter_data(self, uri=None): bucket = None if uri is None: file = self.field.get(self.field.context or self.context) if file is None or file.uri is None: raise FileNotFoundException('File not found') else: uri = file.uri bucket = file._bucket_name downloader = await self._download(uri, bucket) # we do not want to timeout ever from this... # downloader['Body'].set_socket_timeout(999999) async with downloader['Body'] as stream: data = await stream.read(CHUNK_SIZE) while True: if not data: break yield data data = await stream.read(CHUNK_SIZE)
async def iter_data(self, uri=None, **kwargs): bucket = None if uri is None: file = self.field.query(self.field.context or self.context, None) if not _is_uploaded_file(file): raise FileNotFoundException("File not found") else: uri = file.uri bucket = file._bucket_name downloader = await self._download(uri, bucket, **kwargs) # we do not want to timeout ever from this... # downloader['Body'].set_socket_timeout(999999) async with downloader["Body"] as stream: data = await stream.read(CHUNK_SIZE) while True: if not data: break yield data data = await stream.read(CHUNK_SIZE)