Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8484437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:22:50+00:00 2026-06-10T20:22:50+00:00

I am having problems trying to obtain a dataUrl for an image taken with

  • 0

I am having problems trying to obtain a dataUrl for an image taken with the camera using code similar to that used in the sample ‘How to build a location-based hybrid mobile app with reverse geocoding’. I’m testing the code on a Samsung Galaxy S2 with Android 2.3.5.

The code I’m using to get the dataUrl is pretty standard javascript:

var toDataURL = function toDataURL(uri, callback)
{
    forge.logging.log('toDataURL...');
    forge.logging.log(uri);
    var image = document.createElement('img');
    image.src = uri;
    image.onload = function ()
    {
        forge.logging.log('toDataURL image.onload...');

        // create canvas
        var canvas = document.createElement('canvas');
        canvas.id = 'canvas';
        canvas.width = image.width;
        canvas.height = image.height;

        var context = canvas.getContext('2d');

        // draw image to canvas
        context.drawImage(image, 0, 0, image.width, image.height, 0, 0,  canvas.width,  canvas.height);

        // get data url 
        var dataUrl = canvas.toDataURL();
        callback(dataUrl);
        forge.logging.log('...toDataURL image.onload');
    };
    forge.logging.log('...toDataURL');
};

The problem is that the dataUrl returned by canvas.toDataURL is always empty (‘data:,’). The uri passed as a parameter is logged as:

I/Forge (18019): [FORGE] ‘content://io.trigger.forgeb6367d6ee13011e1b9ed12313d1adcbe/file___height=640&type=image&uri=content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F44%23Intent%3Bend&width=480&name=Image’

which is returned from a call to forge.file.URL with parameter:

D/Forge (18019): Native call “file.URL” with task.params: {“uri”:”content://media/external/images/media/45#Intent;end”,”name”:”Image”,”type”:”image”,”width”:480,”height”:640}

Presumably this is something to do with permissions. My question is, what do I have to do to get the code to work? Or is there an alternative approach to getting the content of a file taken with the camera? (My aim is to send the content of the photo to a web service.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:22:52+00:00Added an answer on June 10, 2026 at 8:22 pm

    I’ll take a proper look at the code to try to recreate here – thanks for the snippet – but in the meantime there might be a simpler solution.

    If all you need to do is display the image to the user then upload it to a web service, you can just use file.getImage, file.URL and request.ajax. Cobbled together from code here and here:

    forge.file.getImage({width: 300, height: 300}, function (file) {
      // Get a URL to the returned file object which can be used from the local webview.
      forge.file.URL(file, function (url) {
        document.getElementById('img').src = url;
      });
      forge.request.ajax({
        url: "http://example.com/file_upload",
        files: [file]
      });
    });
    

    Would that work for you?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems trying to use the regular expression that I used in
I'm having problems with trying to catch an error. I'm using Pyramid/SQLAlchemy and made
I am having problems when trying to use a TypedFactoryFacility in Castle. I'm using
I'm having some problems trying to get the code below to output the data
I'm having problems trying to load scripts using the Modernizr version of yepnope and
I've been having problems trying to retrieve a related entity using an HQL subquery.
I am having problems trying to POST a JSON Array. For my Android code,
I'm trying to implement a simple FTP client using winsock. I'm having problems trying
I'm having problems trying to overload the post increment operator in C#. Using integers
I'm having problems trying to run a Java file that uses Apache Lucene. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.