uploadImageAndCreateArtist function
Future<void>
uploadImageAndCreateArtist(- {required String name,
- required File imageFile}
)
Implementation
Future<void> uploadImageAndCreateArtist({
required String name,
required File imageFile,
}) async {
final uri = Uri.parse('https://matrix.nabit.app/backend/api/artist-create');
var request = http.MultipartRequest('POST', uri);
request.fields['name'] = name;
var file = await http.MultipartFile.fromPath('artist_image', imageFile.path);
request.files.add(file);
try {
var response = await request.send();
// Print the response body
var responseBody = await response.stream.transform(utf8.decoder).join();
print(responseBody);
if (response.statusCode == 200) {
toast("Create Succesfully");
} else {
toast('Error please contact the admin: ${response.statusCode}');
print('Response body: $responseBody'); // Print the body for debugging
}
} catch (e) {
print('Error en la solicitud: $e');
throw errorSomethingWentWrong;
}
}