media.capturePhoto() question!

Hello.

How can i tell if someone selected a photo or not?

in docs it says:

  • event.completed will be true if the user selected a photo; false if the user cancelled the camera or photo selection.

but  it will return true if the user select any file.

is there anyway to know if i selected an image or not?

regards,

Carlos.

media.capturePhoto() should only let you select photos.

Thanks Rob for you reply.

i’m using both, media.capturePhoto() for opening the device camera and i’m using media.selectPhoto() to open the images gallery. the problem is in android an user can leave the folder of the image gallery and choose any other file. i tested in build 2015.2642 in android 5.1.1. i can have acess to ASTRO file manager from the gallery and from there select any file.

i tried to use the event.completed to only do stuff if it was return true but will continue my code if i select any other file. I think the code should check when a file is returned and at this point it is only trying to prevent an user to select a non image.

I suppose you could test to see if event.target is a table or nil.  If I remember correctly both will return a display object as event.target.  If we can’t make a display image from it, it should be nil.  The docs say event.completed will be true if they selected a photo.  Is it returning true if you select something else?

If you use selectPhoto, it can copy the file to your sandbox and not create a display object.  If you choose that option, then you can always try and load the file as a display object and see if it works for fails.

Rob

thank you rob for the tips.

when event.completed happens a copy is made to the sandbox, after that i display the image on the display so the user can confirm his selection. when i select a non image, it will create a black image. (it stills returns true in creating an image) in the background i create a copy of the same file (using filters to check if the image exist and only duplicate if thats the case)  so i can send it to the database (i needed to create a copy because i can’t send an image that’s beeing used). it will upload a corrupted image since the source is not an image and then my problems starts…i want to prevent this.

while doing all this, i test if the image exist. all check points i made they all passed.

yes, it is returning true if i select something else. that’s my problem. I think the internal code is not prepared for a non selected image, because it have filters in the beginning trying to not let users select images. in ios i could not select a non image, it will display grey files. in android if i use its browser it will grey files that are not images too. the problem is that android is way open than ios and i can select another file browser easy from the gallery and all files are open for selection. i guess internal code of media.selectPhoto() didn’t expect this could happen and they didn’t use validation after the selection is made.

 i will try the event.target.

We will need you to file a bug report that shows this problem.  Please make sure to include a complete project (main.lua, config.lua and build.settings + any assets needed to run) and use the “Report a bug” link at the top of the page.

Please post the bug # you get in an email from the bug tracker back to this forum post when you get it.

Rob

bug reported. thx for the support, rob.

Can you post the bug # please?

Rob

caseCase #40832.

the official response was: “The media.selectPhoto API is only for selecting photos. If you have installed something else on your device that stores non-photo files in the photo gallery or allows you to select non-photo files, Corona will not handle that.”

if corona gives us an function that returns true if i select a photo and don’t provide a robust way to check if that selection is valid or not, and is our fault of installing apps that makes our life easier and blame users for not doing the “correct” way…i’m speechless. 

my contract ends next month, guess is time to find another alternative than corona. i’ve problems with scrollviews, display.save, media.selectPhoto, tableviews…and the list goes on…is there any function out there without a bug? and believe me the problem is not in my code because i strip it all and just make tests with the corona functions.

I’m pretty sure I tested this on my Nexus 7 and I couldn’t select non-photo files.  But even then, if the user is expecting to open a photo and they access something that’s not a photo, then getting a black image would make thing think “hmmm, I shouldn’t do that again”. 

Rob

i’m not worring about people that do something by mistake. there are people that tries on propose to crash apps and flaws that they can explore. tell apple to tell his costumers that they can’t use a certain kind of message to reboot theirs devices (text messsage bug).

ive 2 nexus 7, old version and new, and i could in both select a non photo image. just open a file explorer…i sent screeshots to the bug report showing that, so i’m pretty sure they are aware of the problem. and in this case since i don’t have access to the original file name i can’t do myself a check file to discard non photos. my code sends automatic photos to the server after selecting and confirming. since the media.photo returns true to any file…it will sent to the server that file…

Just curious, what kinds of tools allow non-photos into the gallery(or image gallery)?

media.capturePhoto() should only let you select photos.

Thanks Rob for you reply.

i’m using both, media.capturePhoto() for opening the device camera and i’m using media.selectPhoto() to open the images gallery. the problem is in android an user can leave the folder of the image gallery and choose any other file. i tested in build 2015.2642 in android 5.1.1. i can have acess to ASTRO file manager from the gallery and from there select any file.

i tried to use the event.completed to only do stuff if it was return true but will continue my code if i select any other file. I think the code should check when a file is returned and at this point it is only trying to prevent an user to select a non image.

I suppose you could test to see if event.target is a table or nil.  If I remember correctly both will return a display object as event.target.  If we can’t make a display image from it, it should be nil.  The docs say event.completed will be true if they selected a photo.  Is it returning true if you select something else?

If you use selectPhoto, it can copy the file to your sandbox and not create a display object.  If you choose that option, then you can always try and load the file as a display object and see if it works for fails.

Rob

thank you rob for the tips.

when event.completed happens a copy is made to the sandbox, after that i display the image on the display so the user can confirm his selection. when i select a non image, it will create a black image. (it stills returns true in creating an image) in the background i create a copy of the same file (using filters to check if the image exist and only duplicate if thats the case)  so i can send it to the database (i needed to create a copy because i can’t send an image that’s beeing used). it will upload a corrupted image since the source is not an image and then my problems starts…i want to prevent this.

while doing all this, i test if the image exist. all check points i made they all passed.

yes, it is returning true if i select something else. that’s my problem. I think the internal code is not prepared for a non selected image, because it have filters in the beginning trying to not let users select images. in ios i could not select a non image, it will display grey files. in android if i use its browser it will grey files that are not images too. the problem is that android is way open than ios and i can select another file browser easy from the gallery and all files are open for selection. i guess internal code of media.selectPhoto() didn’t expect this could happen and they didn’t use validation after the selection is made.

 i will try the event.target.

We will need you to file a bug report that shows this problem.  Please make sure to include a complete project (main.lua, config.lua and build.settings + any assets needed to run) and use the “Report a bug” link at the top of the page.

Please post the bug # you get in an email from the bug tracker back to this forum post when you get it.

Rob

bug reported. thx for the support, rob.

Can you post the bug # please?

Rob

caseCase #40832.

the official response was: “The media.selectPhoto API is only for selecting photos. If you have installed something else on your device that stores non-photo files in the photo gallery or allows you to select non-photo files, Corona will not handle that.”

if corona gives us an function that returns true if i select a photo and don’t provide a robust way to check if that selection is valid or not, and is our fault of installing apps that makes our life easier and blame users for not doing the “correct” way…i’m speechless. 

my contract ends next month, guess is time to find another alternative than corona. i’ve problems with scrollviews, display.save, media.selectPhoto, tableviews…and the list goes on…is there any function out there without a bug? and believe me the problem is not in my code because i strip it all and just make tests with the corona functions.