Skip to content

Commit

Permalink
Fix: Fix upload / download
Browse files Browse the repository at this point in the history
  • Loading branch information
sp committed Aug 15, 2023
1 parent 1ec1a27 commit b05f02e
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 174 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Note

## v0.3.3

- Fix big sized Upload Datei / Download Datei
- Optimize tests
- Update deps

## v0.3.2

- Update deps
Expand Down
Binary file added _assets/big_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 30 additions & 22 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:async/async.dart';
Expand Down Expand Up @@ -185,11 +186,8 @@ class ProffixClient implements BaseProffixClient {
final logoutUri = buildUriPx(restURL,
[_options.apiPrefix, _options.version, _options.loginEndpoint]);

var logoutTask = await _dioClient
.delete(
logoutUri,
)
.timeout(Duration(seconds: _options.timeout));
var logoutTask = await _dioClient.delete(logoutUri,
data: {}).timeout(Duration(seconds: _options.timeout));

// Clear PxSessionId
_pxSessionID = "";
Expand Down Expand Up @@ -441,26 +439,31 @@ class ProffixClient implements BaseProffixClient {
/// Utility method to directly download a file from PRO/Datei
@override
Future<Response> downloadFile({required String dateiNr}) async {
String pxsessionid = await getPxSessionId();
final downloadUri = _getUriUrl(
buildUriPx(restURL, [
_options.apiPrefix,
_options.version,
"PRO/Datei/$dateiNr"
]).toString(),
null);

try {
String pxsessionid = await getPxSessionId();
final downloadUri = _getUriUrl(
buildUriPx(restURL,
[_options.apiPrefix, _options.version, "PRO/Datei/$dateiNr"]),
null);

_dioClient.options.headers["PxSessionId"] = pxsessionid;

return await _dioClient.get(downloadUri,
options: Options(responseType: ResponseType.bytes));
data: {},
options: Options(
responseType: ResponseType.bytes,
));
} catch (e) {
if (e is DioException) {
throw ProffixException(
body: e.response, statusCode: e.response?.statusCode ?? 0);
if (e is ProffixException) {
rethrow;
} else if (e is HttpException) {
throw ProffixException(body: e.message, statusCode: 0);
} else {
throw ProffixException(body: e.toString(), statusCode: 0);
if (e is List<int>) {
throw ProffixException(body: utf8.decode(e), statusCode: 0);
} else {
throw ProffixException(body: e, statusCode: 0);
}
}
}
}
Expand All @@ -475,6 +478,8 @@ class ProffixClient implements BaseProffixClient {

_dioClient.options.headers['PxSessionId'] = pxsessionid;
_dioClient.options.headers["content-type"] = "application/octet-stream";
_dioClient.options.contentType = "application/octet-stream";
_dioClient.options.headers['Content-Length'] = data.length;

Map<String, dynamic> params = {"filename": fileName};
try {
Expand All @@ -485,6 +490,10 @@ class ProffixClient implements BaseProffixClient {
fileName != null ? params : null);

var resp = await _dioClient.post(postUri,
// onSendProgress: (count, total) => {print(count)},
options: Options(
receiveTimeout: Duration(minutes: 2),
sendTimeout: Duration(minutes: 2)),
data: Stream.fromIterable(data.map((e) => [e])));
if (resp.statusCode == null ||
(resp.statusCode! < 200 && resp.statusCode! > 300)) {
Expand All @@ -496,10 +505,9 @@ class ProffixClient implements BaseProffixClient {
return dateiNr;
}
} catch (e) {
if (e is DioException) {
if (e is ProffixException) {
//handle DioError here by error type or by error code
throw ProffixException(
body: e.response, statusCode: e.response?.statusCode ?? 0);
rethrow;
} else {
throw ProffixException(body: e.toString(), statusCode: 0);
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_proffix_rest
description: A Dart wrapper for Proffix Rest API with automatic login and logout and many useful helper functions
version: 0.3.2
version: 0.3.3
repository: https://github.com/pitwch/dart_proffix_rest
homepage: https://github.com/pitwch/dart_proffix_rest
environment:
Expand All @@ -10,7 +10,7 @@ dependencies:
async: ^2.11.0
crypto: ^3.0.2
dartz: ^0.10.1
dio: ^5.3.0
dio: ^5.3.2
intl: ^0.18.1

dev_dependencies:
Expand Down
Loading

0 comments on commit b05f02e

Please sign in to comment.