123456789101112131415161718192021222324252627282930 |
- def upload_file(filepath, bucket_name=None, namekey=None, wait=False):
- """Uploads the given file to S3 storage.
- Arguments
- ---------
- filepath : str
- The full path, from root, to the desired file.
- bucket_name (optional) : str
- The name of the bucket to upload the file to. If not given, it will be
- inferred from any defined base directory that is present on the path
- (there is no guarentee which base directory will be used if several are
- present in the given path). If base directory inferrence fails the
- default bukcet will be used, if defined, else the operation will fail.
- namekey (optional) : bool
- Indicate whether to use the name of the file as the key when uploading
- to the bucket. If set, or if no base directory is found in the
- filepath, the file name will be used as key. Otherwise, the path
- rooted at the detected base directory will be used, resulting in a
- directory-like structure in the S3 bucket.
- wait (optional) : bool
- Defaults to False. If set to True, the function will wait on the upload
- operation. Otherwise, the upload will be performed asynchronously in a
- separate thread.
- """
- filepath = _parse_file_path(filepath)
- bucket, key = _get_bucket_and_key(filepath, bucket_name, namekey)
- if wait:
- bucket.upload_file(filepath, key)
- else:
- _get_executor().submit(_file_upload_thread, bucket, filepath, key)
|