fix: Set Content-Length on upload

This commit is contained in:
Christian Pauly 2021-01-08 11:16:14 +01:00
parent e9933659a0
commit 5ea63b1f1f
3 changed files with 8 additions and 2 deletions

View File

@ -1,3 +1,7 @@
## 0.1.3
- Set Content-Length on upload
## 0.1.2
- Add more encryption and decryption content parsing

View File

@ -1295,16 +1295,18 @@ class MatrixApi {
Future<String> upload(Uint8List file, String fileName,
{String contentType}) async {
fileName = fileName.split('/').last;
final length = file.length;
var headers = <String, String>{};
headers['Authorization'] = 'Bearer $accessToken';
headers['Content-Type'] =
contentType ?? lookupMimeType(fileName, headerBytes: file);
headers['Content-Length'] = length.toString();
fileName = Uri.encodeQueryComponent(fileName);
final url =
'${homeserver.toString()}/_matrix/media/r0/upload?filename=$fileName';
final streamedRequest = http.StreamedRequest('POST', Uri.parse(url))
..headers.addAll(headers);
streamedRequest.contentLength = await file.length;
streamedRequest.contentLength = length;
streamedRequest.sink.add(file);
streamedRequest.sink.close();
var streamedResponse = _testMode ? null : await streamedRequest.send();

View File

@ -1,6 +1,6 @@
name: matrix_api_lite
description: Dead simple data model for the matrix.org client-server API.
version: 0.1.2
version: 0.1.3
homepage: https://famedly.com
environment: