Last active
December 24, 2020 10:28
-
-
Save AliRn76/3b352c46036c01b991280a549cafb9fa to your computer and use it in GitHub Desktop.
send image to al1.best:89..api..add-item
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Take Image From Galery | |
_takeImageGallery() async{ | |
var picture = await ImagePicker.pickImage(source: ImageSource.gallery); | |
setState(() { | |
imageSource = picture; | |
}); | |
} | |
Future<StreamedResponse> sendPostRequest() async{ | |
try{ | |
String image_url; | |
String url = "http://al1.best:89/api/add-item/"; | |
if(imageSource != null){ | |
image_url = imageSource.path; | |
}else{ | |
image_url = null; | |
} | |
// Create a request | |
var request = MultipartRequest('POST', Uri.parse(url)); | |
// Add Request Body | |
if(image_url != null){ | |
request.files.add( | |
await MultipartFile.fromPath( | |
'image_url', | |
image_url | |
) | |
); | |
} | |
request.fields['name'] = nameController.text; | |
request.fields['category'] = category; | |
request.fields['number'] = number.toString(); | |
request.fields['price'] = priceController.text; | |
request.fields['description'] = description.text; | |
final response = await request.send(); | |
print(response.statusCode); | |
final respStr = await response.stream.bytesToString(); | |
print("res: $respStr"); | |
print("statusCode: ${response.statusCode}"); | |
return response; | |
} | |
on Exception catch (exception){ | |
print("Exception: $exception"); | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment