openfoodfacts / smooth-app

🤳🥫 The new Open Food Facts mobile application for Android and iOS, crafted with Flutter and Dart
https://world.openfoodfacts.org/open-food-facts-mobile-app?utm_source=off&utf_medium=web&utm_campaign=github-repo
Apache License 2.0
847 stars 281 forks source link

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

Closed teolemon closed 1 year ago

teolemon commented 1 year ago

What

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 commented 1 year ago

I am having this problem as well.

monsieurtanuki commented 1 year ago

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

FoodCoach-App commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

monsieurtanuki commented 1 year ago

@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 commented 1 year ago

@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

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 commented 1 year ago
monsieurtanuki commented 1 year ago
  • 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 commented 1 year ago
  • 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 commented 1 year ago

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 commented 1 year ago

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

aquilax commented 1 year ago

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

monsieurtanuki commented 1 year ago

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

FoodCoach-App commented 1 year ago

haha, perhaps.

In your successfully OFF image upload, what is/was the request URL?

I'm attempting to use:

https://us.openfoodfacts.org/cgi/product_jqm2.pl?code=0247637306390&user_id=MY_USERNAME&MY_PASSWORD&product_image_upload.pl/imgupload_front=imagename.jpg

but it's not working.

The response status is: no code or invalid code

What code OFF looking for?

On Tue, Jan 3, 2023 at 12:13 PM monsieurtanuki @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/openfoodfacts/smooth-app/issues/3490#issuecomment-1370021474, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4J6ZUF53WZ7RJSRWAT6BC3WQRMZ3ANCNFSM6AAAAAATMGSCKQ . You are receiving this because you were mentioned.Message ID: @.***>

FoodCoach-App commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

4.1.0 876 is latest internal, in sync with the repository

teolemon commented 1 year ago

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

teolemon commented 1 year ago

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

teolemon commented 1 year ago

@monsieurtanuki has set up extra logging

aquilax commented 1 year ago

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

teolemon commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

monsieurtanuki commented 1 year ago

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:

Am I right?

What if you slightly crop the image?

teolemon commented 1 year ago

Bingo, it works on recrop

monsieurtanuki commented 1 year ago

Yoohoo!

I'll fix it today.

For the anecdote