[BUG] Fix upload attachment
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class ComposerAPI {
|
||||
@@ -11,9 +13,15 @@ class ComposerAPI {
|
||||
ComposerAPI(this._dioClient);
|
||||
|
||||
Future<UploadResponse> uploadAttachment(UploadRequest uploadRequest) async {
|
||||
final file = File(uploadRequest.fileInfo.filePath);
|
||||
final headerParam = _dioClient.getHeaders();
|
||||
headerParam[HttpHeaders.contentTypeHeader] = uploadRequest.fileInfo.mimeType;
|
||||
headerParam[HttpHeaders.contentLengthHeader] = file.readAsBytesSync().length;
|
||||
|
||||
final resultJson = await _dioClient.post(
|
||||
Uri.decodeFull(uploadRequest.uploadUrl.toString()),
|
||||
data: File(uploadRequest.fileInfo.filePath).readAsBytesSync());
|
||||
return UploadResponse.fromJson(resultJson);
|
||||
options: Options(headers: headerParam),
|
||||
data: file.openRead());
|
||||
return UploadResponse.fromJson(jsonDecode(resultJson));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user