Added file upload in talk
This commit is contained in:
30
lib/api/marianumcloud/files-sharing/fileSharingApi.dart
Normal file
30
lib/api/marianumcloud/files-sharing/fileSharingApi.dart
Normal file
@ -0,0 +1,30 @@
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/http.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'fileSharingApiParams.dart';
|
||||
|
||||
class FileSharingApi {
|
||||
Future<void> share(FileSharingApiParams query) async {
|
||||
var preferences = await SharedPreferences.getInstance();
|
||||
|
||||
Map<String, String> headers = {};
|
||||
headers.putIfAbsent("Accept", () => "application/json");
|
||||
headers.putIfAbsent("OCS-APIRequest", () => "true");
|
||||
|
||||
Uri endpoint = Uri.https("${preferences.getString("username")!}:${preferences.getString("password")!}@cloud.marianum-fulda.de", "/ocs/v2.php/apps/files_sharing/api/v1/shares", query.toJson().map((key, value) => MapEntry(key, value.toString())));
|
||||
|
||||
log("request file share");
|
||||
Response response = await http.post(endpoint, headers: headers);
|
||||
|
||||
if(response.statusCode != HttpStatus.ok) {
|
||||
throw Exception("Api call failed with ${response.statusCode}: ${response.body}");
|
||||
} else {
|
||||
log("File share successfull: ${response.body}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'fileSharingApiParams.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class FileSharingApiParams {
|
||||
int shareType;
|
||||
String shareWith;
|
||||
String path;
|
||||
String? referenceId;
|
||||
String? talkMetaData;
|
||||
|
||||
FileSharingApiParams({
|
||||
required this.shareType,
|
||||
required this.shareWith,
|
||||
required this.path,
|
||||
this.referenceId,
|
||||
this.talkMetaData
|
||||
});
|
||||
|
||||
factory FileSharingApiParams.fromJson(Map<String, dynamic> json) => _$FileSharingApiParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$FileSharingApiParamsToJson(this);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'fileSharingApiParams.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
FileSharingApiParams _$FileSharingApiParamsFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
FileSharingApiParams(
|
||||
shareType: json['shareType'] as int,
|
||||
shareWith: json['shareWith'] as String,
|
||||
path: json['path'] as String,
|
||||
referenceId: json['referenceId'] as String?,
|
||||
talkMetaData: json['talkMetaData'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$FileSharingApiParamsToJson(
|
||||
FileSharingApiParams instance) =>
|
||||
<String, dynamic>{
|
||||
'shareType': instance.shareType,
|
||||
'shareWith': instance.shareWith,
|
||||
'path': instance.path,
|
||||
'referenceId': instance.referenceId,
|
||||
'talkMetaData': instance.talkMetaData,
|
||||
};
|
Reference in New Issue
Block a user