MushroomObserver / mushroom-observer

A website for sharing observations of mushrooms.
https://mushroomobserver.org
MIT License
77 stars 25 forks source link

Image upload via api #2265

Open ChrisNeefus opened 1 month ago

ChrisNeefus commented 1 month ago

Has something changed in the past few months the would prevent an app from uploading images to mo via the api?

nimmolo commented 1 month ago

No, I don't believe so. Our MO app uses the same API too. When did it stop working?

@mo-nathan's currently working on updating the mobile app and may be able to say more, but nothing has changed in the API at all, as far as I know. @JoeCohen is also using the API to build a new feature importing a user's observations from iNaturalist.

ChrisNeefus commented 1 month ago

I'm not certain when, but I first noticed it in May. It was working ok last fall. The issue seems to be that MO is expecting the upload as a reference to a local (on the iPhone) file rather than as data attached to an HTTP request. I'm not familiar with ruby, but digging a little, api2->core->uploads.rb does seem to provide for image uploads via data included in an HTTP request.

Here is part of the response from MO `

2024-07-31 15:07:26 API2::RenderFailed
There was a problem while rendering the results. Weird: file.path is blank! /var/web/mo/app/models/image.rb:530:in `init_image_from_local_file' /var/web/mo/app/models/image.rb:506:in `image=' /home/mo/.gem/ruby/3.3.0/gems/activemode `
ChrisNeefus commented 1 month ago

The issue may be in app/models/image.rb. At line 504 it determines that the image is in a (temporary?) file, even though the the variable "file" is nil at that point.

def image=(file) self.upload_handle = file if local_file?(file) init_image_from_local_file(file) elsif input_stream?(file) init_image_from_stream(file) else raise("Unexpected image upload class, #{file.class.name}.") end end

JoeCohen commented 1 month ago

@ChrisNeefus: How can i replicate the problem?

ChrisNeefus commented 1 month ago

I’ll work on that.

From: Joseph D. Cohen @.> Date: Wednesday, July 31, 2024 at 6:33 PM To: MushroomObserver/mushroom-observer @.> Cc: Christopher Neefus @.>, Mention @.> Subject: Re: [MushroomObserver/mushroom-observer] Image upload via api (Issue #2265) CAUTION: This email originated from outside of the University System. Do not click links or open attachments unless you recognize the sender and know the content is safe.

@ChrisNeefushttps://github.com/ChrisNeefus: How can i replicate the problem?

— Reply to this email directly, view it on GitHubhttps://github.com/MushroomObserver/mushroom-observer/issues/2265#issuecomment-2261568934, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AC4X7W2ACRZN7R5B4FSGTD3ZPFQ23AVCNFSM6AAAAABLWMOGCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRRGU3DQOJTGQ. You are receiving this because you were mentioned.Message ID: @.***>

ChrisNeefus commented 2 weeks ago

Hi Joe,

I haven't figured out a way for you to recreate the issue. You can download my app (mushroomlog) from the apple app store and you will find that the observation upload to MO works for the data, but not the images. To see the error message, you would need to be in XCode and working on the source. I did see that a user of the Mushroom Observer iPhone app reported that the image upload in your app didn't work either, so perhaps that would be a better for you to debug the issue.

I've seen the note on the MO website that you are looking for help with the Android app. I can't help with that, but if you need help with the iPhone version, I'd be willing to lend a hand.

Chris

mo-nathan commented 2 weeks ago

Hi Chris,

I've been working in Xcode on the MO mobile app and not having any trouble with file uploads from React Native. I'm trying to focus on getting some features into the mobile app before the NEMF foray in mid October, so I don't have a huge amount of time at the moment, but I'd be interested to know what the error messages are that you're seeing. I'm not sure what other reported errors you're referring to.

What tech stack is your app using?

Best, Nathan

On Thu, Sep 5, 2024 at 8:30 AM ChrisNeefus @.***> wrote:

Hi Joe,

I haven't figured out a way for you to recreate the issue. You can download my app (mushroomlog) from the apple app store and you will find that the observation upload to MO works for the data, but not the images. To see the error message, you would need to be in XCode and working on the source. I did see that a user of the Mushroom Observer iPhone app reported that the image upload in your app didn't work either, so perhaps that would be a better for you to debug the issue.

I've seen the note on the MO website that you are looking for help with the Android app. I can't help with that, but if you need help with the iPhone version, I'd be willing to lend a hand.

Chris

— Reply to this email directly, view it on GitHub https://github.com/MushroomObserver/mushroom-observer/issues/2265#issuecomment-2331428608, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYQDUSQHEFVQDMX2PD6RUTZVBFHLAVCNFSM6AAAAABLWMOGCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZRGQZDQNRQHA . You are receiving this because you were mentioned.Message ID: @.***>

ChrisNeefus commented 2 weeks ago

Hi Nathan,

Thanks for the response. My app (MushroomLog) is written in Swift. It is uploading images as Data in the HTTP request through the MO API2. It was working fine last fall. I first noticed the issue in May. Observations upload fine, but image uploads fail. It seems like the issue may be in api2->core->uploads.rb, which does seem to provide for image uploads via data included in an HTTP request, but for some reason, it is trying to get the image from a local file. Running the app in the Xcode simulator, the first error appears at line 506 in uploads.rb. I’ve attached the full console error messages, but I think the most relevant are this:

2024-07-31 15:07:26 API2::RenderFailed
There was a problem while rendering the results. Weird: file.path is blank! /var/web/mo/app/models/image.rb:530:in `init_image_from_local_file' /var/web/mo/app/models/image.rb:506:in `image=' /home/mo/.gem/ruby/3.3.0/gems/activemode I’ve attached my Swift code for the module that uploads observations and images to MO. The observation upload begins on line 350 and works fine. The image upload (uploadSelectedImage) begins on line 627. The Mushroom Observer iPhone app review I referred to in my previous comment was on the Apple App Store. It say “Needs TLC (bug/lacking) Uploaded my first observation after downloading. Once it uploaded I went to my observation tab (1/3 tabs total in the app) and the preview shows no photo although I did upload 2 ….”. But I looked at the review again and it is from a year ago, so I don’t think it was the same problem since my app was working fine then. I plan to be at NEMF in October. I look forward to seeing you there. Are you doing a presentation on MO? Take Care, Chris  > On Sep 5, 2024, at 11:41 AM, Nathan Wilson ***@***.***> wrote: > > > CAUTION: This email originated from outside of the University System. Do not click links or open attachments unless you recognize the sender and know the content is safe. > > > > Hi Chris, > > I've been working in Xcode on the MO mobile app and not having any trouble > with file uploads from React Native. I'm trying to focus on getting some > features into the mobile app before the NEMF foray in mid October, so I > don't have a huge amount of time at the moment, but I'd be interested to > know what the error messages are that you're seeing. I'm not sure what > other reported errors you're referring to. > > What tech stack is your app using? > > Best, > Nathan > > On Thu, Sep 5, 2024 at 8:30 AM ChrisNeefus ***@***.***> wrote: > > > Hi Joe, > > > > I haven't figured out a way for you to recreate the issue. You can > > download my app (mushroomlog) from the apple app store and you will find > > that the observation upload to MO works for the data, but not the images. > > To see the error message, you would need to be in XCode and working on the > > source. I did see that a user of the Mushroom Observer iPhone app reported > > that the image upload in your app didn't work either, so perhaps that would > > be a better for you to debug the issue. > > > > I've seen the note on the MO website that you are looking for help with > > the Android app. I can't help with that, but if you need help with the > > iPhone version, I'd be willing to lend a hand. > > > > Chris > > > > — > > Reply to this email directly, view it on GitHub > > , > > or unsubscribe > > > > . > > You are receiving this because you were mentioned.Message ID: > > ***@***.***> > > > — > Reply to this email directly, view it on GitHub , or unsubscribe . > You are receiving this because you were mentioned. >
mo-nathan commented 1 week ago

Thanks Chris,

The error message you report is actually a relatively recent (March 2024) update from Jason (@pellaea). See:

https://github.com/MushroomObserver/mushroom-observer/pull/2019

I'm not sure what the motivation was for that change, but it's possible that it unintentionally broke you.

I'm going to add a bit more logging to MO to see if we can figure out what happened. I did not write this code, so debugging it is going to be slow for me given all the other stuff I have on my plate at the moment. It's possible that @pellaea would be able to move faster on this.

Best, Nathan

mo-nathan commented 1 week ago

Deployed a bit more logging. Please try again. I don't expect it will fix anything, but hopefully it will give us a bit more information in the error message.

ChrisNeefus commented 1 week ago

Hi Nathan,

Thanks for looking into it. I just uploaded a Baorangia observation with 3 images. The image upload failed.

Upload an observation in the XCode simulator with 1 image. Image failed. Error messages in the Xcode console are the same as before. MO API2 doesn't seem to recognize that the image is part of the HTTP request data and tries to process it as a local file.

Sent from my iPhone

On Sep 7, 2024, at 11:23 AM, Nathan Wilson @.***> wrote:



CAUTION: This email originated from outside of the University System. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Deployed a bit more logging. Please try again. I don't expect it will fix anything, but hopefully it will give us a bit more information in the error message.

— Reply to this email directly, view it on GitHubhttps://github.com/MushroomObserver/mushroom-observer/issues/2265#issuecomment-2335481698, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AC4X7W5OPZV6EEVNIENSJJTZVMK63AVCNFSM6AAAAABLWMOGCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZVGQ4DCNRZHA. You are receiving this because you were mentioned.Message ID: @.***>

ChrisNeefus commented 1 week ago

Hi Nathan,

Would it be possible to send me a code snippet for the image upload from the MO ios app that I can compare to my app? The easiest solution might be to modify my code to match.

Chris