in airavata_django_portal_sdk/user_storage/api.py [0:0]
def open_file(request, data_product=None, data_product_uri=None):
"""
Return file object for replica if it exists in user storage. One of
`data_product` or `data_product_uri` is required.
"""
if data_product is None:
data_product = _get_data_product(request, data_product_uri)
if remoteapi.is_remote_api_configured():
resp = remoteapi.call(
request,
"/download",
params={'data-product-uri': data_product.productUri},
base_url="/sdk",
raise_for_status=False)
remoteapi.raise_if_404(resp, f"File does not exist for data product {data_product.productUri}")
resp.raise_for_status()
file = io.BytesIO(resp.content)
disposition = resp.headers['Content-Disposition']
disp_value, disp_params = cgi.parse_header(disposition)
# Give the file object a name just like a real opened file object
file.name = disp_params['filename']
return file
else:
storage_resource_id, path = _get_replica_resource_id_and_filepath(data_product)
backend = get_user_storage_provider(request,
owner_username=data_product.ownerName,
storage_resource_id=storage_resource_id)
return backend.open(path)