@@ -37,6 +37,7 @@ import 'package:uuid/uuid.dart';
3737
3838import './api_request_data.dart' ;
3939import './api_request_part.dart' ;
40+ import './body_part_data.dart' ;
4041import './byte_data_extensions.dart' ;
4142import './requests/batch_request.dart' ;
4243import '../aspose_words_cloud.dart' ;
@@ -62,13 +63,21 @@ class ApiClient {
6263
6364 _encryptorInitialized = true ;
6465 try {
65- final rsaPublicKey = await _publicKeyRequester (GetPublicKeyRequest ());
66- if (rsaPublicKey == null || rsaPublicKey.modulus == null || rsaPublicKey.exponent == null ) {
67- throw ApiException (400 , 'Invalid public key response.' );
66+ var exponentString = configuration.rsaExponent;
67+ var modulusString = configuration.rsaModulus;
68+
69+ if (exponentString == null || exponentString.isEmpty || modulusString == null || modulusString.isEmpty)
70+ {
71+ final rsaPublicKey = await _publicKeyRequester (GetPublicKeyRequest ());
72+ if (rsaPublicKey == null || rsaPublicKey.modulus == null || rsaPublicKey.exponent == null ) {
73+ throw ApiException (400 , 'Invalid public key response.' );
74+ }
75+ exponentString = rsaPublicKey.modulus as String ;
76+ modulusString = rsaPublicKey.exponent as String ;
6877 }
6978
70- final modulus = BigInt .parse (hex.encode (base64Decode (rsaPublicKey.modulus as String )), radix: 16 );
71- final exponent = BigInt .parse (hex.encode (base64Decode (rsaPublicKey.exponent as String )), radix: 16 );
79+ final modulus = BigInt .parse (hex.encode (base64Decode (modulusString )), radix: 16 );
80+ final exponent = BigInt .parse (hex.encode (base64Decode (exponentString )), radix: 16 );
7281 var pubKey = RSAPublicKey (modulus, exponent);
7382
7483 _encrypter.init (true , PublicKeyParameter <RSAPublicKey >(pubKey));
@@ -333,29 +342,54 @@ class ApiClient {
333342 return result;
334343 }
335344
336- Map <String , ByteData > deserializeMultipartMap (final ByteData data) {
337- var result = < String , ByteData > {};
345+ Map <String , BodyPartData > deserializeMultipartMap (final ByteData data) {
346+ var result = < String , BodyPartData > {};
338347 for (final part in _deserializeMultipartBase (data)) {
339348 var headersEndIndex = part.indexOf (_newline2x);
340349 if (headersEndIndex == null ) {
341350 throw ApiException (400 , 'Failed to parse multipart response.' );
342351 }
343352
353+ const contentDispositionStr = 'Content-Disposition:' ;
354+ const contentTypeStr = 'Content-Disposition:' ;
344355 var headersData = ByteData .sublistView (part, 0 , headersEndIndex);
345356 var headersStr = utf8.decoder.convert (headersData.buffer.asUint8List (headersData.offsetInBytes, headersData.lengthInBytes));
346- var contentDisposition = headersStr.split ('\r\n ' ).firstWhere ((x) => x.trim ().startsWith ('Content-Disposition:' ));
357+ var headersRaw = headersStr.split ('\r\n ' );
358+ var contentDisposition = headersRaw.firstWhere ((x) => x.trim ().startsWith (contentDispositionStr)).replaceFirst (contentDispositionStr, '' ).trim ();
359+ var contentType = headersRaw.firstWhere ((x) => x.trim ().startsWith (contentTypeStr))? .replaceFirst (contentTypeStr, '' )? .trim ();
347360 var nameHeaderPart = contentDisposition.split (';' ).map ((x) => x.trim ()).firstWhere ((x) => x.toLowerCase ().startsWith ('name' ));
361+ var filenameHeaderPart = contentDisposition.split (';' ).map ((x) => x.trim ()).firstWhere ((x) => x.toLowerCase ().startsWith ('name' ));
348362 var nameValueParts = nameHeaderPart.split ('=' );
363+ var filenameValueParts = filenameHeaderPart? .split ('=' );
349364 if (nameValueParts.length != 2 ) {
350365 throw ApiException (400 , 'Failed to parse multipart response.' );
351366 }
352367
353- var nameValue = nameValueParts.elementAt (1 ).trim ().toLowerCase ();
354- result[nameValue] = ByteData .sublistView (part, headersEndIndex + _newline2x.lengthInBytes, part.lengthInBytes - _newline.lengthInBytes);
368+ var nameValue = nameValueParts.elementAt (1 ).trim ().replaceAll ('"' , '' ).toLowerCase ();
369+ var filenameValue = filenameValueParts? .elementAt (1 )? .trim ()? .replaceAll ('"' , '' );
370+ var content = ByteData .sublistView (part, headersEndIndex + _newline2x.lengthInBytes, part.lengthInBytes - _newline.lengthInBytes);
371+ result[nameValue] = BodyPartData (contentType, filenameValue, content);
355372 }
356373 return result;
357374 }
358375
376+ Map <String , ByteData > deserializeFilesCollection (final BodyPartData bodyPartData) {
377+ var result = < String , ByteData > {};
378+ if (bodyPartData.contentType != null && bodyPartData.contentType.startsWith ('multipart/mixed' ))
379+ {
380+ var subParts = deserializeMultipartMap (bodyPartData.content);
381+ subParts.forEach ((key, value) {
382+ result[value.filename] = value.content;
383+ });
384+ }
385+ else
386+ {
387+ result[bodyPartData.filename ?? '' ] = bodyPartData.content;
388+ }
389+
390+ return result;
391+ }
392+
359393 dynamic deserializeBatchPart (final RequestBase request, final ByteData partData) {
360394 var statusDataEndIndex = partData.indexOf (_newline);
361395 if (statusDataEndIndex == null ) {
@@ -471,7 +505,7 @@ class ApiClient {
471505
472506 var httpRequest = http.Request (requestData.method, Uri .parse (requestData.url));
473507 httpRequest.headers['x-aspose-client' ] = 'dart sdk' ;
474- httpRequest.headers['x-aspose-client-version' ] = '22.2 ' ;
508+ httpRequest.headers['x-aspose-client-version' ] = '22.3 ' ;
475509 httpRequest.headers['Authorization' ] = await _getAuthToken ();
476510 if (requestData.headers != null ) {
477511 httpRequest.headers.addAll (requestData.headers);
0 commit comments