Skip to content

m8ty_client_files

m8ty_client_files solves this by providing one typed interface for uploading, listing, viewing, downloading, and deleting files, so apps can implement controlled file journeys consistently.

It’s a security risk to have multiple endpoint to manage file uploads. The mitigate this issue this API has been created.

Check the documentation of the m8ty_client_files library to get an idea about the available models and their properties.

import 'package:dio/dio.dart';
import 'package:m8ty_client_files/m8ty_client_files.dart';
import 'package:m8ty_client_common/m8ty_client_common.dart';
import 'package:built_collection/built_collection.dart';

Here some examples how the dart client can be used

final client = M8tyClientFiles();
client.setOAuthToken('ApiOAuth2', oauthToken);
final api = client.getFilesApi();
try {
final response = await api.uploadFile(
file: MultipartFile.fromFile('path/to/file.pdf', filename: 'file.pdf'),
);
print('Uploaded: ${response.data}');
} on DioException catch (e) {
throw Exception(
'Request failed (status: ${e.response?.statusCode}): ${e.response?.data}',
);
}
final client = M8tyClientFiles();
client.setOAuthToken('ApiOAuth2', oauthToken);
final api = client.getFilesApi();
final Response<Uint8List> response = await api.downloadFile(
fileId: '1234',
);
File file = File("/temp/myfile");
await file.writeAsBytes(response.data!);
final client = M8tyClientFiles();
client.setOAuthToken('ApiOAuth2', oauthToken);
final api = client.getFilesApi();
final response = await api.listFiles();
final client = M8tyClientFiles();
client.setOAuthToken('ApiOAuth2', oauthToken);
final api = client.getFilesApi();
await api.deleteFile(
fileId: '1234',
);
final client = M8tyClientFiles();
client.setOAuthToken('ApiOAuth2', oauthToken);
final api = client.getFilesApi();
final response = await api.viewFile(
fileId: '1234',
);