addProductImage static method
Future<Status>
addProductImage(
- User user,
- SendImage image, {
- UriProductHelper uriHelper = uriHelperFoodProd,
Send one image to the server. The image will be added to the product specified in the SendImage Returns a Status object as result.
User myUser = User(userId: "username", password: "secret_password");
String barcode = "0000000000000";
SendImage image = SendImage(
lang: OpenFoodFactsLanguage.FRENCH,
barcode: barcode,
imageField: ImageField.FRONT,
imageUri: Uri.parse("path_to_my_image"),
);
Status status = await OpenFoodAPIClient.addProductImage(myUser, image);
if (status.status != 1) {
print(
"An error occured while sending the picture : ${status.statusVerbose}");
return;
}
print("Upload was successful");
Implementation
static Future<Status> addProductImage(
User user,
SendImage image, {
final UriProductHelper uriHelper = uriHelperFoodProd,
}) async {
var dataMap = <String, String>{};
var fileMap = <String, Uri>{};
dataMap.addAll(image.toData());
fileMap.putIfAbsent(image.getImageDataKey(), () => image.imageUri);
var imageUri = uriHelper.getUri(
path: '/cgi/product_image_upload.pl',
addUserAgentParameters: false,
);
return await HttpHelper().doMultipartRequest(
imageUri,
dataMap,
files: fileMap,
user: user,
uriHelper: uriHelper,
);
}