collect icon indicating copy to clipboard operation
collect copied to clipboard

Automatic conversion of image files to .jpg prior to submission to Briefcase or Aggregate.

Open danielsteward opened this issue 8 years ago • 13 comments
trafficstars

Collect v1.7.1 (but all versions as far as I know), Android v6.0.1, Fairphone 2.

Problem description: Collect renames all image files to .jpg extension whatever the android device creates and is submitting only .jpgs to Aggregate

Steps to reproduce the problem: Create an image other than a on the phone and attempt to add it to a form. The image is renamed with a .jpg extension

Expected behavior: Possibly this IS the expected behaviour although this is connected to other issues with Briefcase and Aggregate and needs to be rationalised across the board. See issue https://github.com/opendatakit/briefcase/issues/5 and https://github.com/opendatakit/briefcase/issues/33

If anyone knows what the original purpose of this conversion to .jpg is please comment.

danielsteward avatar Jun 19 '17 10:06 danielsteward

The conversion takes place in the class collect\android\activities\FormEntryActivity within the methods onActivityResult() L 629 and saveChosenImage() L 819.

danielsteward avatar Jun 19 '17 12:06 danielsteward

OK, update. I am not sure that this is a bug as such. With my testing of how Collect, Briefcase and Aggregate work together it seems that Aggregate can only handle jpg image types. If you try to push an instance from Briefcase to Aggregate, substituting a gif for a jpg the image doesn’t display in Aggregate. And Collect simply converts an image to a jpg whatever the image type chosen. So we can either work with this or amend Aggregate so that it can handle image types other than jpgs. I’m not sure where to take this next. Any ideas team?

danielsteward avatar Jul 06 '17 13:07 danielsteward

@danielsteward Thanks for the great detective work!

@mitchellsundt @wbrunette Is it true that Aggregate can only handle JPGs? I'd love some insight as to why that is the case and what potential workarounds are.

yanokwa avatar Jul 07 '17 20:07 yanokwa

Aggregate can handle any content, but when displaying the little thumbnails on the Submissions pages, it executes this codepath https://github.com/opendatakit/aggregate/blob/master/src/main/java/org/opendatakit/aggregate/servlet/BinaryDataServlet.java#L213 to scale down the image.

And that prevents handling anything other than JPG.

The underlying library might be able to support more file formats. The code is here: https://github.com/opendatakit/aggregate/tree/master/src/main/java/org/opendatakit/aggregate/util with different implementations for AppEngine (using a Google service) and Tomcat. The Tomcat code uses this library: https://github.com/opendatakit/aggregate-components/tree/master/TomcatUtils which uses a hacked imageio library with a bunch of licensed / proprietary format handlers removed https://github.com/jai-imageio/jai-imageio-core

mitchellsundt avatar Jul 07 '17 22:07 mitchellsundt

And collect shouldn't have any restrictions on file types. I don't think you're reading the code correctly if you see anything like that.

mitchellsundt avatar Jul 07 '17 22:07 mitchellsundt

@mitchellsundt Collect doesn't have restrictions on file types, but it does rename any image to jpg before uploading. https://github.com/opendatakit/collect/blob/master/collect_app/src/main/java/org/odk/collect/android/activities/FormEntryActivity.java#L656 is the relevant line of code.

This is bad behavior on the part of Collect and I think we should probably fix it. But it does break Aggregate, so we'd need to get a fix in place first. With the information you provided, would this be contributor friendly?

yanokwa avatar Jul 07 '17 22:07 yanokwa

I'd be happy to take something like this on if I have guidance from a Java master. That is exactly what I'm looking for here to improve my coding and expand my knowledge. Especially if it is with ODK.

danielsteward avatar Jul 08 '17 17:07 danielsteward

True. I support this.

On the other hand, is there a possibility to manipulate the images from BLOB to a url that the image can be saved in a directory on the file server? Some manipulation of the sort?

kusaasira avatar Aug 03 '17 07:08 kusaasira

The possibility to store images files in a directory on the server should be great, or maybe just a script to easily convert blob to file. At the moment it's not so easy to get and use collected images.

mathieubossaert avatar Aug 04 '17 07:08 mathieubossaert

@kusaasira @mathieubossaert Agreed that easier access to images on Aggregate would be a nice thing, but it's not relevant to this issue. If you'd like to see this discussed, please file an issue at https://github.com/opendatakit/opendatakit/issues

yanokwa avatar Aug 04 '17 14:08 yanokwa

Sorry for the "pollution", here is the new issue : https://github.com/opendatakit/opendatakit/issues/1313

mathieubossaert avatar Aug 04 '17 15:08 mathieubossaert

@yanokwa @mathieubossaert the issue opendatakit/opendatakit#1313 was closed unanimously hence I thought we would get a better way forward from here.

kusaasira avatar Dec 11 '17 08:12 kusaasira

@kusaasira This issue is about keeping PNGs submitted by Collect as PNGs instead of changing their extension to jpg. The discussion of image handling on Aggregate is now at https://github.com/opendatakit/aggregate/issues/164.

lognaturel avatar Dec 12 '17 00:12 lognaturel