Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaging and ingredient photo upload does not work on existing products #3490

Closed
teolemon opened this issue Dec 29, 2022 · 28 comments · Fixed by #3524
Closed

Packaging and ingredient photo upload does not work on existing products #3490

teolemon opened this issue Dec 29, 2022 · 28 comments · Fixed by #3524
Labels
🐛 bug Something isn't working image upload 🎯 P0

Comments

@teolemon
Copy link
Member

What

  • Packaging and ingredient photo upload does not work on existing products

Steps to reproduce the behavior

  1. Go to an existing product
  2. Click on Add packaging photo or Add Ingredient photo if missing
  3. Crop/Validate…
  4. See that no photo placeholder appears or is uploaded
@FoodCoach-App
Copy link

I am having this problem as well.

@monsieurtanuki
Copy link
Contributor

@teolemon @FoodCoach-App Please provide barcode examples (and related packaging or ingredient photos).

@FoodCoach-App
Copy link

I'm setting up the API and am having problems uploading an image data to UPC 0247637306390

The URL request is: https://us.openfoodfacts.org/cgi/product_jqm2.pl?code=0247637306390&user_id=MY_USER_ID&password=MY_PASSWORD&&product_image_upload.pl/imgupload_front=image_front.jpg

This is a POST request from Xano if that matters.

I'm attempting to follow this example:
https://openfoodfacts.github.io/api-documentation/#jump-4WRITERequests-Addanewproduct
and this example:
https://openfoodfacts.github.io/openfoodfacts-server/introduction/api/

But they differ on several points.

@FoodCoach-App
Copy link

FoodCoach-App commented Jan 3, 2023

This is NOT with the OpenFoodFacts app. I'm attempting to use existing API calls to allow FoodCoach users to add and take pictures of foods for OFF from FoodCoach.

@teolemon
Copy link
Member Author

teolemon commented Jan 3, 2023

@monsieurtanuki happens on all products without an ingredients photo
Link for a scannable barcode: barcode-8056446541685

@monsieurtanuki
Copy link
Contributor

@teolemon Thank you but I cannot scan, remember?
The barcode is enough.
I'll upload a photo of my holidays on the French Riviera as an ingredients photo.

@monsieurtanuki
Copy link
Contributor

@teolemon To be honest this is not a picture from the French Riviera but that's not the point.
The point is that I managed to upload an ingredient picture in the first try with the app:
https://fr.openfoodfacts.org/produit/8056446541685/fagioli-cannellini-the-brand

I went to

  • the product page
  • add basis data ("Compléter les informations de base")
  • I clicked on the "add photo ingredients" icon in the gallery

Why I may not have worked for you:

  1. for some reason you didn't click on the same button
  2. the background task is still pending or has failed (and is therefore still pending) - you can check in DEV MODE / Pending tasks
  3. the picture you tried to send is already somewhere in the database - the server does not like that and make the call fail - which brings you back to point 2

@teolemon
Copy link
Member Author

teolemon commented Jan 3, 2023

  • I tried from the carrousel, from the Photos section in editing, and now from the basic info as well. Same issue in all cases
  • No failed tasks, on wifi.
  • New pictures from my camera, so no chance it's in the DB
  • Are you testing on a physical device ?

@monsieurtanuki
Copy link
Contributor

  • I tried from the carrousel, from the Photos section in editing, and now from the basic info as well. Same issue in all cases

I tried only from basic info. Please provide other barcodes if you want me to try with the carrousel (product page top, right?) and the edit photo / crop page

  • No failed tasks, on wifi.

OK

  • New pictures from my camera, so no chance it's in the DB

OK

  • Are you testing on a physical device ?

No this is still not possible for me (cf. #2849)

@aquilax
Copy link

aquilax commented Jan 3, 2023

  • I tried from the carrousel, from the Photos section in editing, and now from the basic info as well. Same issue in all cases
  • New pictures from my camera, so no chance it's in the DB

Getting the same result when i try.

@monsieurtanuki
Copy link
Contributor

I'm setting up the API and am having problems uploading an image data to UPC 0247637306390

@FoodCoach-App @teolemon Done from the product page top carrousel:

Capture d’écran 2023-01-03 à 18 07 52
Capture d’écran 2023-01-03 à 18 08 37
Capture d’écran 2023-01-03 à 18 10 50

https://fr.openfoodfacts.org/produit/0247637306390

@monsieurtanuki
Copy link
Contributor

Could be a "waterfall pictures only" filter on the server... ;)

@aquilax
Copy link

aquilax commented Jan 3, 2023

Or maybe the version? I'm on Android 4.1.0+847

@monsieurtanuki
Copy link
Contributor

@aquilax I don't know anything about the version numbers. I work on the latest github code.

@FoodCoach-App
Copy link

FoodCoach-App commented Jan 3, 2023 via email

@FoodCoach-App
Copy link

The "no code or invalid code" is when I was attempting to upload images with "put".

I get "fields saved", but no update to the image when using "get".

@monsieurtanuki
Copy link
Contributor

@FoodCoach-App Please have a look at:

https://github.com/openfoodfacts/smooth-app/blob/develop/packages/smooth_app/lib/background/background_task_image.dart#L138-L150

  /// Uploads the product image.
  @override
  Future<void> upload() async {
    final SendImage image = SendImage(
      lang: getLanguage(),
      barcode: barcode,
      imageField: ImageField.fromOffTag(imageField)!,
      imageUri: Uri.parse(imagePath),
    );

    // TODO(AshAman999): check returned Status
    await OpenFoodAPIClient.addProductImage(getUser(), image);
  }

And https://github.com/openfoodfacts/openfoodfacts-dart/blob/master/lib/src/open_food_api_client.dart#L155-L182

  /// Send one image to the server.
  /// The image will be added to the product specified in the SendImage
  /// Returns a Status object as result.
  static Future<Status> addProductImage(
    User user,
    SendImage image, {
    QueryType? queryType,
  }) 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',
      queryType: queryType,
      addUserAgentParameters: false,
    );

    return await HttpHelper().doMultipartRequest(
      imageUri,
      dataMap,
      files: fileMap,
      user: user,
      queryType: queryType,
    );
  }

And perhaps https://github.com/openfoodfacts/openfoodfacts-dart/blob/master/lib/src/model/send_image.dart

@teolemon
Copy link
Member Author

teolemon commented Jan 3, 2023

4.1.0 876 is latest internal, in sync with the repository

@teolemon
Copy link
Member Author

teolemon commented Jan 4, 2023

Mmmmh, note that it also happens on the nutrition fact photo

@teolemon
Copy link
Member Author

teolemon commented Jan 5, 2023

@aquilax @FoodCoach-App Can you try uploading with the latest version of the app, and copy paste what ADB mentions

@teolemon
Copy link
Member Author

teolemon commented Jan 5, 2023

@monsieurtanuki has set up extra logging

@aquilax
Copy link

aquilax commented Jan 5, 2023

@teolemon can you help me found out how to get a dev build?

@teolemon
Copy link
Member Author

teolemon commented Jan 5, 2023

Ok, I can't upload on product addition either
https://world-fr.openfoodfacts.org/produit/3263854938111/uu-yu

@aquilax it's build from source, of the internal in the README, but I'm not sure it logs everything

@AshAman999
Copy link
Member

AshAman999 commented Jan 5, 2023

Hello @teolemon

I did just try to add a pic and it worked, I clicked to upload from the carousel,
I am on the latest release from test flight
app version 4.1.0+885-ml-ios

https://world.openfoodfacts.org/product/3263854938111/uu-yu

@teolemon
Copy link
Member Author

teolemon commented Jan 5, 2023

I'm on Android 13, on a Pixel, for what it's worth.

@monsieurtanuki
Copy link
Contributor

I'm on Android 13, on a Pixel, for what it's worth.

@teolemon So you tried on your Android 13 Pixel, you went to a Crop page, you clicked on Confirm and nothing happened:

  • no ADB log
  • no dialog
  • no snackbar

Am I right?

What if you slightly crop the image?

@teolemon
Copy link
Member Author

teolemon commented Jan 5, 2023

Bingo, it works on recrop

@monsieurtanuki
Copy link
Contributor

Yoohoo!

I'll fix it today.

For the anecdote

  • in all "edit" pages there's a check each time a user exits the page: if something changed and the user tries to exit the page, there's a dialog (cf. Inconsistent "save before quitting page?" dialogs #3516)
  • special case: the user clicks on "save" without having changed anything - we consider there's nothing to do and therefore do nothing, we just exit the page (that partly caused the bug)
  • how do we consider that the user changed something? In that page: have the crop values changed, and has the image been retaken on the crop page?
  • what is wrong here is the "has the image been retaken on the crop page" part, meaning "has anything changed with the picture itself?". For a brand new image it's virtually "changed" as it comes from nowhere (I'm not starting a religious argument here) . For an existing image it's different: it is "not changed", unless the user explicitly retakes a picture.
  • therefore the fix is to make a difference between "brand new picture" and "existing picture".
  • it was very difficult for me to test that, because I cannot take picture and so I reused default pictures on my iphone emulator (mainly waterfalls, I don't know why).
  • and reusing the same pictures again and again, as the server would reject them and say "No way, I already know this picture, upload is rejected", I systematically (slightly) cropped the pictures to create "new" slightly different pictures...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working image upload 🎯 P0
Development

Successfully merging a pull request may close this issue.

5 participants