Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/dart-package-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ jobs:
run: dart format lib test -l 80 --set-exit-if-changed

- name: analyzer
run: |
if [ "${{ matrix.sdk }}" == "stable" ]; then
dart analyze --fatal-warnings .
else
dart analyze
fi
if: ${{ matrix.sdk == 'stable'}}
run: dart analyze --fatal-warnings .

- name: Start Docker services
if: ${{ inputs.needs-docker }}
Expand Down
12 changes: 9 additions & 3 deletions packages/storage_client/lib/src/storage_file_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,22 @@ class StorageFileApi {
/// name. For example `download('folder/image.png')`.
///
/// [transform] download a transformed variant of the image with the provided options
Future<Uint8List> download(String path, {TransformOptions? transform}) async {
///
/// [queryParams] additional query parameters to be added to the URL
Future<Uint8List> download(String path,
{TransformOptions? transform, Map<String, String>? queryParams}) async {
final wantsTransformations = transform != null;
final finalPath = _getFinalPath(path);
final renderPath =
wantsTransformations ? 'render/image/authenticated' : 'object';
final queryParams = transform?.toQueryParams;

Map<String, String> query = transform?.toQueryParams ?? {};
query.addAll(queryParams ?? {});

final options = FetchOptions(headers: headers, noResolveJson: true);

var fetchUrl = Uri.parse('$url/$renderPath/$finalPath');
fetchUrl = fetchUrl.replace(queryParameters: queryParams);
fetchUrl = fetchUrl.replace(queryParameters: query);

final response =
await _storageFetch.get(fetchUrl.toString(), options: options);
Expand Down
19 changes: 19 additions & 0 deletions packages/storage_client/test/basic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void main() {
tearDown(() {
final file = File('a.txt');
if (file.existsSync()) file.deleteSync();
customHttpClient.receivedRequests.clear();
});

group('Client with custom http client', () {
Expand Down Expand Up @@ -153,6 +154,24 @@ void main() {
expect(String.fromCharCodes(response), 'Updated content');
});

test('should download public file with query params', () async {
final file = File('a.txt');
file.writeAsStringSync('Updated content');

customHttpClient.response = file.readAsBytesSync();

final response = await client
.from('public_bucket')
.download('b.txt', queryParams: {'version': '1'});
expect(response, isA<Uint8List>());
expect(String.fromCharCodes(response), 'Updated content');

expect(customHttpClient.receivedRequests.length, 1);

final request = customHttpClient.receivedRequests.first;
expect(request.url.queryParameters, {'version': '1'});
});

test('should get public URL of a path', () {
final response = client.from('files').getPublicUrl('b.txt');
expect(response, '$objectUrl/public/files/b.txt');
Expand Down
5 changes: 4 additions & 1 deletion packages/storage_client/test/custom_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ class RetryHttpClient extends BaseClient {
}

class CustomHttpClient extends BaseClient {
int statusCode = 201;
dynamic response;
List<BaseRequest> receivedRequests = <BaseRequest>[];

@override
Future<StreamedResponse> send(BaseRequest request) async {
receivedRequests.add(request);
final dynamic body;
if (response is Uint8List) {
body = response;
Expand All @@ -47,7 +50,7 @@ class CustomHttpClient extends BaseClient {

return StreamedResponse(
Stream.value(body),
201,
statusCode,
request: request,
);
}
Expand Down