uploadToIpfs method
Implementation
Future<String> uploadToIpfs(String uploadPath) async {
try {
final bytes = File(uploadPath).readAsBytesSync();
final response = await http.post(
Uri.parse('https://api.nft.storage/upload'),
headers: {
'Authorization': 'Bearer $storageKey',
'content-type': 'image/*'
},
body: bytes,
);
final data = jsonDecode(response.body);
final cid = data['value']['cid'];
debugPrint('CID OF IMAGE -> $cid');
return cid;
} catch (e) {
debugPrint('Error at IPFS Service - uploadImage: $e');
rethrow;
}
}