TF-56 Send email with attachment
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
class AuthorizationInterceptors extends InterceptorsWrapper {
|
||||
String? _authorization;
|
||||
|
||||
String getBasicAuth() => _authorization ?? '';
|
||||
|
||||
void changeAuthorization(String? userName, String? password) {
|
||||
_authorization = base64Encode(utf8.encode('$userName:$password'));
|
||||
}
|
||||
@@ -12,7 +15,7 @@ class AuthorizationInterceptors extends InterceptorsWrapper {
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||
if (_authorization != null) {
|
||||
options.headers['Authorization'] = 'Basic $_authorization';
|
||||
options.headers[HttpHeaders.authorizationHeader] = 'Basic $_authorization';
|
||||
}
|
||||
super.onRequest(options, handler);
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ class DownloadClient {
|
||||
|
||||
Future<ResponseBody> downloadFile(
|
||||
String url,
|
||||
String baseAuth,
|
||||
String basicAuth,
|
||||
CancelToken? cancelToken,
|
||||
) async {
|
||||
final headerParam = _dioClient.getHeaders();
|
||||
headerParam[HttpHeaders.authorizationHeader] = baseAuth;
|
||||
headerParam[HttpHeaders.authorizationHeader] = basicAuth;
|
||||
headerParam[HttpHeaders.acceptHeader] = DioClient.jmapHeader;
|
||||
|
||||
final responseBody = await _dioClient.get(
|
||||
|
||||
@@ -14,14 +14,14 @@ class DownloadManager {
|
||||
String downloadUrl,
|
||||
Future<Directory> directoryToSave,
|
||||
String filename,
|
||||
String baseAuth,
|
||||
String basicAuth,
|
||||
{CancelToken? cancelToken}
|
||||
) async {
|
||||
final streamController = StreamController<String>();
|
||||
|
||||
try {
|
||||
await Future.wait([
|
||||
_downloadClient.downloadFile(downloadUrl, baseAuth, cancelToken),
|
||||
_downloadClient.downloadFile(downloadUrl, basicAuth, cancelToken),
|
||||
directoryToSave
|
||||
]).then((values) {
|
||||
final fileStream = (values[0] as ResponseBody).stream;
|
||||
|
||||
Reference in New Issue
Block a user