diff --git a/packages/shorebird_code_push_client/lib/src/code_push_client.dart b/packages/shorebird_code_push_client/lib/src/code_push_client.dart index 5c7df722..08da2942 100644 --- a/packages/shorebird_code_push_client/lib/src/code_push_client.dart +++ b/packages/shorebird_code_push_client/lib/src/code_push_client.dart @@ -147,11 +147,12 @@ class CodePushClient { json.decode(body) as Map, ); - final uploadResponse = await _httpClient.put( - Uri.parse(decoded.url), - body: File(artifactPath).readAsBytesSync(), - ); - if (uploadResponse.statusCode != HttpStatus.ok) { + final uploadRequest = http.MultipartRequest('POST', Uri.parse(decoded.url)) + ..files.add(file); + + final uploadResponse = await _httpClient.send(uploadRequest); + + if (uploadResponse.statusCode != HttpStatus.noContent) { throw CodePushException( message: '''Failed to upload artifact (${uploadResponse.reasonPhrase} '${uploadResponse.statusCode})''', @@ -195,11 +196,12 @@ class CodePushClient { json.decode(body) as Map, ); - final uploadResponse = await _httpClient.put( - Uri.parse(decoded.url), - body: File(artifactPath).readAsBytesSync(), - ); - if (uploadResponse.statusCode != HttpStatus.ok) { + final uploadRequest = http.MultipartRequest('POST', Uri.parse(decoded.url)) + ..files.add(file); + + final uploadResponse = await _httpClient.send(uploadRequest); + + if (uploadResponse.statusCode != HttpStatus.noContent) { throw CodePushException( message: '''Failed to upload artifact (${uploadResponse.reasonPhrase} '${uploadResponse.statusCode})''', diff --git a/packages/shorebird_code_push_client/lib/src/version.dart b/packages/shorebird_code_push_client/lib/src/version.dart index 957ca59e..7e495581 100644 --- a/packages/shorebird_code_push_client/lib/src/version.dart +++ b/packages/shorebird_code_push_client/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '0.6.0+1'; +const packageVersion = '0.6.0+2'; diff --git a/packages/shorebird_code_push_client/pubspec.yaml b/packages/shorebird_code_push_client/pubspec.yaml index 4c7c2b5c..203a3859 100644 --- a/packages/shorebird_code_push_client/pubspec.yaml +++ b/packages/shorebird_code_push_client/pubspec.yaml @@ -1,6 +1,6 @@ name: shorebird_code_push_client description: Library which allows Dart applications to interact with the ShoreBird CodePush API -version: 0.6.0+1 +version: 0.6.0+2 repository: https://github.com/shorebirdtech/shorebird publish_to: none diff --git a/packages/shorebird_code_push_client/test/src/code_push_client_test.dart b/packages/shorebird_code_push_client/test/src/code_push_client_test.dart index 958de7fc..1f60de2d 100644 --- a/packages/shorebird_code_push_client/test/src/code_push_client_test.dart +++ b/packages/shorebird_code_push_client/test/src/code_push_client_test.dart @@ -246,34 +246,30 @@ void main() { test('throws an exception if the upload fails', () async { const artifactId = 42; const uploadUrl = 'https://example.com'; - when(() => httpClient.send(any())).thenAnswer((invocation) async { - final request = - invocation.positionalArguments.first as http.BaseRequest; - if (request.method == 'POST') { - return http.StreamedResponse( - Stream.value( - utf8.encode( - json.encode( - CreatePatchArtifactResponse( - id: artifactId, - patchId: patchId, - arch: arch, - platform: platform, - hash: hash, - size: size, - url: uploadUrl, - ), + final responses = [ + http.StreamedResponse( + Stream.value( + utf8.encode( + json.encode( + CreatePatchArtifactResponse( + id: artifactId, + patchId: patchId, + arch: arch, + platform: platform, + hash: hash, + size: size, + url: uploadUrl, ), ), ), - HttpStatus.ok, - ); - } - return http.StreamedResponse( - const Stream.empty(), - HttpStatus.badRequest, - ); - }); + ), + HttpStatus.ok, + ), + http.StreamedResponse(Stream.empty(), HttpStatus.badRequest), + ]; + when(() => httpClient.send(any())).thenAnswer( + (_) async => responses.removeAt(0), + ); final tempDir = Directory.systemTemp.createTempSync(); final fixture = File(path.join(tempDir.path, 'release.txt')) @@ -301,7 +297,7 @@ void main() { .last as http.BaseRequest; expect(request.url, equals(Uri.parse(uploadUrl))); expect( - request.contentLength, + (request as http.MultipartRequest).files.single.length, equals(fixture.readAsBytesSync().lengthInBytes), ); }); @@ -309,34 +305,30 @@ void main() { test('completes when request succeeds', () async { const artifactId = 42; const uploadUrl = 'https://example.com'; - when(() => httpClient.send(any())).thenAnswer((invocation) async { - final request = - invocation.positionalArguments.first as http.BaseRequest; - if (request.method == 'POST') { - return http.StreamedResponse( - Stream.value( - utf8.encode( - json.encode( - CreatePatchArtifactResponse( - id: artifactId, - patchId: patchId, - arch: arch, - platform: platform, - hash: hash, - size: size, - url: uploadUrl, - ), + final responses = [ + http.StreamedResponse( + Stream.value( + utf8.encode( + json.encode( + CreatePatchArtifactResponse( + id: artifactId, + patchId: patchId, + arch: arch, + platform: platform, + hash: hash, + size: size, + url: uploadUrl, ), ), ), - HttpStatus.ok, - ); - } - return http.StreamedResponse( - const Stream.empty(), + ), HttpStatus.ok, - ); - }); + ), + http.StreamedResponse(Stream.empty(), HttpStatus.noContent), + ]; + when(() => httpClient.send(any())).thenAnswer( + (_) async => responses.removeAt(0), + ); final tempDir = Directory.systemTemp.createTempSync(); final fixture = File(path.join(tempDir.path, 'release.txt')) @@ -527,34 +519,30 @@ void main() { test('throws an exception if the upload fails', () async { const artifactId = 42; const uploadUrl = 'https://example.com'; - when(() => httpClient.send(any())).thenAnswer((invocation) async { - final request = - invocation.positionalArguments.first as http.BaseRequest; - if (request.method == 'POST') { - return http.StreamedResponse( - Stream.value( - utf8.encode( - json.encode( - CreateReleaseArtifactResponse( - id: artifactId, - releaseId: releaseId, - arch: arch, - platform: platform, - hash: hash, - size: size, - url: uploadUrl, - ), + final responses = [ + http.StreamedResponse( + Stream.value( + utf8.encode( + json.encode( + CreateReleaseArtifactResponse( + id: artifactId, + releaseId: releaseId, + arch: arch, + platform: platform, + hash: hash, + size: size, + url: uploadUrl, ), ), ), - HttpStatus.ok, - ); - } - return http.StreamedResponse( - const Stream.empty(), - HttpStatus.badRequest, - ); - }); + ), + HttpStatus.ok, + ), + http.StreamedResponse(Stream.empty(), HttpStatus.badRequest), + ]; + when(() => httpClient.send(any())).thenAnswer( + (_) async => responses.removeAt(0), + ); final tempDir = Directory.systemTemp.createTempSync(); final fixture = File(path.join(tempDir.path, 'release.txt')) @@ -583,7 +571,7 @@ void main() { ).captured.last as http.BaseRequest; expect(request.url, equals(Uri.parse(uploadUrl))); expect( - request.contentLength, + (request as http.MultipartRequest).files.single.length, equals(fixture.readAsBytesSync().lengthInBytes), ); }); @@ -591,34 +579,30 @@ void main() { test('completes when request succeeds', () async { const artifactId = 42; const uploadUrl = 'https://example.com'; - when(() => httpClient.send(any())).thenAnswer((invocation) async { - final request = - invocation.positionalArguments.first as http.BaseRequest; - if (request.method == 'POST') { - return http.StreamedResponse( - Stream.value( - utf8.encode( - json.encode( - CreateReleaseArtifactResponse( - id: artifactId, - releaseId: releaseId, - arch: arch, - platform: platform, - hash: hash, - size: size, - url: uploadUrl, - ), + final responses = [ + http.StreamedResponse( + Stream.value( + utf8.encode( + json.encode( + CreateReleaseArtifactResponse( + id: artifactId, + releaseId: releaseId, + arch: arch, + platform: platform, + hash: hash, + size: size, + url: uploadUrl, ), ), ), - HttpStatus.ok, - ); - } - return http.StreamedResponse( - const Stream.empty(), + ), HttpStatus.ok, - ); - }); + ), + http.StreamedResponse(Stream.empty(), HttpStatus.noContent), + ]; + when(() => httpClient.send(any())).thenAnswer( + (_) async => responses.removeAt(0), + ); final tempDir = Directory.systemTemp.createTempSync(); final fixture = File(path.join(tempDir.path, 'release.txt'))