This is a migrated thread and some comments may be shown as answers.

In camera function how can I pass both destination type data url and file url in one function

3 Answers 430 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Arun
Top achievements
Rank 1
Arun asked on 15 Jun 2013, 07:31 AM
In camera function how can I pass both destination type data url and file url in one function

Following is my code

function camera() 
    {
               
      navigator.camera.getPicture(onSuccess, onFail, {
      quality: 50,
      destinationType: Camera.DestinationType.DATA_URL
     
          
    }); 

    function onSuccess(imageData)
     {
        
      here in imageData I will be getting the image data a i need to get the image uri as well i.e the value obtained from 
   destinationType: Camera.DestinationType.FILE_URL
                 
    }

3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 17 Jun 2013, 11:06 AM
Hello Arun,

Navigator.camera.getPicture cannot return both DATA_URL and FILE_URI (see Cordova Camera API). If you need to save the picture and have a way to display it as well, use Data URI css technique e.g.:

url('data:image/png;base64,BASE64_DATA') /* From where you stored you base64 data */

Make sure to change the content type depending on the MIME type of the image you’re embedding. Additionally make sure to keep the data URI all on one line without line-breaks.

Regards,
Steve
Telerik

Looking for tips & tricks directly from the Icenium team? Check out our blog!
Missed our first webinar, watch it here.
Share feedback and vote for features on our Feedback Portal.
0
Matt
Top achievements
Rank 1
answered on 22 Jan 2014, 01:26 AM
Steve,

The problem is you don't get the file name or mime type back on this call.   If you the allow the user to pick any media file, then you don't know if they chose JPEG, MPEG, etc.

Arun,

You can't do what you want in one camera call.  As far as I can tell, you have to use FILE_URI first to get the file name and type.  In that callback, then use readAsDataURL with a file reader to get the base64.  It is too bad that DATA_URL doesn't also return the metadata.  

Matt
0
Fernando
Top achievements
Rank 1
answered on 24 Feb 2016, 01:52 PM
Here is a example of how to get file name and base64 image: http://stackoverflow.com/questions/34850386/socket-io-chat-app-that-can-also-send-image-and-even-file
Tags
General Discussion
Asked by
Arun
Top achievements
Rank 1
Answers by
Steve
Telerik team
Matt
Top achievements
Rank 1
Fernando
Top achievements
Rank 1
Share this question
or