Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Need to wait until media.capturePhoto is done saving the file
Started by danielr0 Feb 17 2016 05:54 PM

4 replies to this topic

Best Answer RedBeach , 17 February 2016 - 06:28 PM

Hi Daniel.

 

Yes, there is a listener function and you actually have it written already on your code above!

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

danielr0

[GLOBAL: userInfoPane.html]
danielr0
  • Enthusiast

  • 44 posts
  • Corona SDK

Hey there, I need to know if there is a good way to wait until the image is saved to the destination.

I'm using the following

media.capturePhoto({listener=captured, destination = {baseDir = system.TemporaryDirectory, filename = "file.jpg", type = "image"}})

Then, in the captured function I am trying to send the image as an smtp attachment, but the image hasn't saved yet before the code is called so I end up with a file-doesn't-exist exception.

 

I tried placing code after media.capturePhoto as well, but it seems that this code is called almost immediately after and also doesn't give the system time to save the image to disk.

 

How can I wait until the image is saved by the media.capturePhoto function?

Is there an event listener?

 

My options I can think of right now:

I just hack a workaround and wait 5 seconds?

I manually save the image by not including the destination table, allowing the captured function to receive the image as a display object, saving that display object to disk and finally passing that file to smtp.



[TOPIC: post.html]
#2

RedBeach

[GLOBAL: userInfoPane.html]
RedBeach
  • Corona Geek

  • 1,132 posts
  • Corona SDK

  Best Answer

Hi Daniel.

 

Yes, there is a listener function and you actually have it written already on your code above!



[TOPIC: post.html]
#3

danielr0

[GLOBAL: userInfoPane.html]
danielr0
  • Enthusiast

  • 44 posts
  • Corona SDK

My apologies, turns out I hadn't set the correct base directory when doing an io.path in the SMTP function. It was trying to look for the file in the documents directory when I had saved it to the temporary directory.

 

Also for those of you doing something similar, don't forget to adjust the timeout to a higher value to give the function time to upload the image.

 

If you're using the native mail popup, this stuff isn't an issue, but I wanted to bypass user interaction in this step, hence all the fuss.



[TOPIC: post.html]
#4

RedBeach

[GLOBAL: userInfoPane.html]
RedBeach
  • Corona Geek

  • 1,132 posts
  • Corona SDK

Daniel,

 

I think you are referring to the timeout on network.request, right?  The timeout is only when you don't get any answer from the other side, so the app give up waiting. During upload, there is a constant exchange of data, so the timeout shouldn't be a problem.



[TOPIC: post.html]
#5

danielr0

[GLOBAL: userInfoPane.html]
danielr0
  • Enthusiast

  • 44 posts
  • Corona SDK

I'm talking about require("socket.smtp").send() function.

For some reason, I kept getting timeout exception messages when attaching large files (1MB or more). I added timeout = 60 to the options table and that had solved it.




[topic_controls]
[/topic_controls]