iPhone's readAsDataURL on a temp directory?

323 views
Skip to first unread message

Yoh Suzuki

unread,
Oct 11, 2011, 7:40:33 PM10/11/11
to phonegap
Hello. I'm using the Camera API with DestinationType.FILE_URI to get
the captured image location. I'm remembering this image location, and
I can display it as the src of an HTML img, and upload it to my web
services using readAsDataURL.

However, on the iPhone, it errors out when I try to use
readAsDataURL. It returns error code 1 (FileError.NOT_FOUND_ERR).
It's showing up correctly in the img src, but I can't seem to use
readAsDataURL.

Does anyone know the reason? Is it because it's the temporary
location returned by the Camera API?

The file location looks like this: "file://localhost/var/mobile/
Applications/____/Documents/tmp/____.jpg".

Yoh Suzuki

unread,
Oct 11, 2011, 8:27:28 PM10/11/11
to phonegap
I followed this other post (http://groups.google.com/group/phonegap/
browse_thread/thread/c476b2224ddd2003) and copied the image from the
tmp directory to the permanent directory. I still get error code 1
(FileError.NOT_FOUND_ERR) when I try to readAsDataURL on the permanent
file URI. Is anyone else using readAsDataURL on iPhone? Any help is
appreciated. (I had this problem in 1.0.0 and I'm still having it
after upgrading to 1.1.0).

Becka11y

unread,
Oct 12, 2011, 2:51:29 PM10/12/11
to phonegap

I'm curious as to why you don't just use the DestinationType.DATA_URL
from the camera api? Or, you could use the FileTransfer api to
transmit the image to your server? Otherwise, I'm not sure why the
readAsDataURL would not work as long as you are passing a valid
filePath. readAsDataURL does expect a file object but it can also use
a valid filePath - NOT a file URI. Please post the relevant parts of
your code.

-becky

Yoh Suzuki

unread,
Oct 12, 2011, 3:22:13 PM10/12/11
to phon...@googlegroups.com
Thank you for your response!  Those are good ideas.  However, there are some reasons why I couldn't do some of those things.

Sending thing to the server happens opportunistically, not as a direct response to taking the camera picture.  I'm storing the URI instead of the entire base64 encoded DATA_URL string because I don't want to have to keep it around in localStorage in between application launches.  

(BTW, does anyone know if localStorage has the typical 5 MB limit via PhoneGap?  Also, does "per origin" translate to "per application" in PhoneGap?)

I cannot use the FileTransfer API because my REST service uses basic authentication, and the current build of PhoneGap does not have a way to configure what to send in the header of the request.  I may end up using / writing plugins to do this (I think I saw that someone's already worked on this) to avoid loading the base64 encoded string into JavaScript memory.

[RESOLVED] I think my problem was, as you mentioned, that I was using the file URI instead of the file path.  It worked in Android, the way I had written it, which threw me off.  I just got it working for both iOS and Android by using the file object instead.

Thanks again,

Yoh


--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com



--
Yoh Suzuki, Developer

no...@jobstore.com

unread,
Aug 22, 2017, 7:32:49 AM8/22/17
to phonegap, ysu...@clicktime.com
Hi, I have been trying to resolve this issue for the past two weeks. Can you please help? Would it be better if I share my code or would it be okay if I take a look at yours. 

Hope to hear from you soon!
Regards, 
Nour

Kerri Shotts

unread,
Aug 22, 2017, 7:35:36 AM8/22/17
to phonegap, ysu...@clicktime.com
Do not resurrect old threads -- you replied to a thread from 2011! a LOT has changed since then.

Create a new thread instead.

On Tuesday, August 22, 2017 at 7:32:49 AM UTC-4, no...@jobstore.com wrote:
...


On Thursday, October 13, 2011 at 3:22:13 AM UTC+8, Yoh Suzuki wrote:
...
Reply all
Reply to author
Forward
0 new messages