Skip to content

Instantly share code, notes, and snippets.

@warcayac
Created May 14, 2022 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warcayac/fdffe5e8282e39752af5fd963dd16789 to your computer and use it in GitHub Desktop.
Save warcayac/fdffe5e8282e39752af5fd963dd16789 to your computer and use it in GitHub Desktop.
How to upload images by using HttpReqService
import 'package:wnetworking/wnetworking.dart';
// maximum : 5 elements
const plant = [
{
'imgUrl': 'https://my.plantnet.org/images/image_1.jpeg',
'organ': 'flower',
'imgLocal': 'assets/images/image_1.jpeg',
},
{
'imgUrl': 'https://my.plantnet.org/images/image_2.jpeg',
'organ': 'leaf',
'imgLocal': 'assets/images/image_2.jpeg',
},
];
class PlantNet {
// if not works then visit: https://my.plantnet.org/account/settings
static const apiKey = '1111111111111111111111111111111';
static const _baseUrl = 'https://my-api.plantnet.org/v2';
static const url = '$_baseUrl/identify/all?api-key=$apiKey';
/* ---------------------------------------------------------------------------- */
static Future<JMap?> getInfoWithRemoteImages() async {
print('Start fetching...');
return await HttpReqService
.get<JMap>(url + plant.map<String>((m) => '&images=${m['imgUrl']}&organs=${m['organ']}').join())
.whenComplete(() => print('Fetching done!\n'));
}
/* ---------------------------------------------------------------------------- */
static Future<JMap?> getInfoWithLocalImages() async {
print('Start fetching...');
return await HttpReqService
.post<JMap>(
url,
body: {
'organs': plant.first['organ']!,
'organs': plant.last['organ']!,
},
multipart: {
'images': plant.first['imgLocal']!,
'images': plant.last['imgLocal']!,
},
)
.whenComplete(() => print('Fetching done!\n'));
}
}
void main(List<String> args) async {
// var info = await PlantNet.getInfoWithRemoteImages();
var info = await PlantNet.getInfoWithLocalImages();
print(info.toString());
print('\nDone!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment