Download an object using an s3:// URI.
Convenience function that accepts s3:// URIs and automatically extracts the bucket name and object key. If the bucket differs from the current configuration, it temporarily switches to that bucket for the operation.
@param[in] uri The s3:// URI (e.g., 's3://bucket-name/path/to/object') @param[out] content The downloaded content as an allocatable string @return .true. if download succeeded, .false. on error
character(len=:), allocatable :: content
logical :: success
! Download from different bucket using URI
success = s3_get_uri('s3://other-bucket/data/file.txt', content)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | uri | |||
character(len=:), | intent(out), | allocatable | :: | content |
function s3_get_uri(uri, content) result(success) character(len=*), intent(in) :: uri character(len=:), allocatable, intent(out) :: content logical :: success character(len=:), allocatable :: bucket, key type(s3_config) :: temp_config logical :: uri_parsed success = .false. ! Try to parse as s3:// URI call parse_s3_uri(uri, bucket, key, uri_parsed) if (.not. uri_parsed) then ! Not a s3:// URI, treat as regular key with current config success = s3_get_object(uri, content) return end if ! Use parsed bucket if different from current config if (allocated(bucket) .and. len_trim(bucket) > 0) then temp_config = current_config temp_config%bucket = bucket call s3_init(temp_config) success = s3_get_object(key, content) ! Restore original config call s3_init(current_config) else success = s3_get_object(key, content) end if end function s3_get_uri