m8ty_client_files
Package overview
Section titled “Package overview”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.
Before you start
Section titled “Before you start”Check the documentation of the m8ty_client_files library to get an idea about the available models and their properties.
import all needed libraries
Section titled “import all needed libraries” 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';How to perform different tasks
Section titled “How to perform different tasks”Here some examples how the dart client can be used
Upload a file
Section titled “Upload a file” 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}', ); }Download a file
Section titled “Download a file” 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!);List all files
Section titled “List all files” final client = M8tyClientFiles(); client.setOAuthToken('ApiOAuth2', oauthToken);
final api = client.getFilesApi(); final response = await api.listFiles();Delete a file
Section titled “Delete a file” final client = M8tyClientFiles(); client.setOAuthToken('ApiOAuth2', oauthToken);
final api = client.getFilesApi(); await api.deleteFile( fileId: '1234', );View a file
Section titled “View a file” final client = M8tyClientFiles(); client.setOAuthToken('ApiOAuth2', oauthToken);
final api = client.getFilesApi(); final response = await api.viewFile( fileId: '1234', );© m8ty GmbH 2023 · m8ty.eu
