Gen3 File Class

class gen3.file.Gen3File(endpoint=None, auth_provider=None)[source]

Bases: object

For interacting with Gen3 file management features.

A class for interacting with the Gen3 file download services. Supports getting presigned urls right now.

Parameters:

auth_provider (Gen3Auth) – A Gen3Auth class instance.

Examples

This generates the Gen3File class pointed at the sandbox commons while using the credentials.json downloaded from the commons profile page.

>>> auth = Gen3Auth(refresh_file="credentials.json")
... file = Gen3File(auth)
delete_file(guid)[source]

This method is DEPRECATED. Use delete_file_locations() instead. Delete all locations of a stored data file and remove its record from indexd

Parameters:

guid (str) – provide a UUID for file id to delete

Returns:

requests.delete text result

Return type:

text

delete_file_locations(guid)[source]

Delete all locations of a stored data file and remove its record from indexd

Parameters:

guid (str) – provide a UUID for file id to delete

Returns:

requests.delete result

Return type:

requests.Response

download_single(object_id, path)[source]

Download a single file using its GUID.

Parameters:
  • object_id (str) – The file’s unique ID

  • path (str) – Path to store the downloaded file at

get_presigned_url(guid, protocol=None)[source]

Generates a presigned URL for a file.

Retrieves a presigned url for a file giving access to a file for a limited time.

Parameters:
  • guid (str) – The GUID for the object to retrieve.

  • protocol (str, optional) – The protocol to use for picking the available URL for generating the presigned URL.

Examples

>>> Gen3File.get_presigned_url(query)
upload_file(file_name, authz=None, protocol=None, expires_in=None, bucket=None)[source]

Get a presigned url for a file to upload

Parameters:
  • file_name (str) – file_name to use for upload

  • authz (list) – authorization scope for the file as list of paths, optional.

  • protocol (str) – Storage protocol to use for upload: “s3”, “az”. If this isn’t set, the default will be “s3”

  • expires_in (int) – Amount in seconds that the signed url will expire from datetime.utcnow(). Be sure to use a positive integer. This value will also be treated as <= MAX_PRESIGNED_URL_TTL in the fence configuration.

  • bucket (str) – Bucket to upload to. The bucket must be configured in the Fence instance’s ALLOWED_DATA_UPLOAD_BUCKETS setting. If not specified, Fence defaults to the DATA_UPLOAD_BUCKET setting.

Returns:

json representation for the file upload

Return type:

Document

upload_file_to_guid(guid, file_name, protocol=None, expires_in=None, bucket=None)[source]

Get a presigned url for a file to upload to the specified existing GUID

Parameters:
  • file_name (str) – file_name to use for upload

  • protocol (str) – Storage protocol to use for upload: “s3”, “az”. If this isn’t set, the default will be “s3”

  • expires_in (int) – Amount in seconds that the signed url will expire from datetime.utcnow(). Be sure to use a positive integer. This value will also be treated as <= MAX_PRESIGNED_URL_TTL in the fence configuration.

  • bucket (str) – Bucket to upload to. The bucket must be configured in the Fence instance’s ALLOWED_DATA_UPLOAD_BUCKETS setting. If not specified, Fence defaults to the DATA_UPLOAD_BUCKET setting.

Returns:

json representation for the file upload

Return type:

Document