5 Replies Latest reply on Apr 5, 2012 6:28 AM by oscar soza

    Am I running into a cross domain problem?

      So I'm working with my test app and its on a live server....

       

      I'm on the ET1 in my app and I'm trying to take a picture, then I'm saving it to the device (with the idea it'd later be uploaded) - but I'm trying to display it from the device (using file:///mnt/sdcard/image.jpg )... Can I do this or is it considered a cross domain request (even though I'm accessing the local device)?

       

      Thanks!

        • Re: Am I running into a cross domain problem?
          Robert Galvin

          Ron

           

          That is considered cross domain as well. For that reason we added a simple web server that you can enable via the config.xml. Look at the help documentation in the configuration section. There is a WebServer tag section that allows you to enable it and set the default port and folder.

           

          Rob

            • Re: Am I running into a cross domain problem?

              Rob,

              Hmm... so how can i utilize my live web server with my application and the local device web server to solve this problem (aside from the obvious of storing the application on the device - which isn't an option in this scenario)? Even if I enable the device web server - how does this solve my current problem...?

               

              I did have one idea for trying to solve my problem which gets around the cross domain issues - Is there a way to take a picture, take the raw data, store it as a blob in the websql database and then use javascript to reconstitute it as an image at runtime?

                • Re: Am I running into a cross domain problem?

                  To clarify what I'm looking for now - I'd like to be able to take a picture and have the image data returned to a javascript variable (or object). Once that's done, if its not already in base64, I can convert it to base 64 for inline display or storage in WebSQL... I'd even settle for a way to display the captured image in an HTML 5 canvas because it can be read from there...

                   

                  Is there a way to do this?

                   

                  EDIT : Also - let me explain why this is important: Say for instance that my application exists online - I've stored a cache of the application and DB locally on the device, now I go out of the coverage area and I need to fall back to the local version - If I need to take a picture I can't upload it to the live server (because I'm disconnected) and I can't save it to the device (because of cross domain issues) - so that image has to go somewhere. We need a way to take the image, get it to the local database, so that it can be synced when coverage is restored.

                    • Re: Am I running into a cross domain problem?
                      Robert Galvin

                      Ron

                       

                      The RhoElements Imager object can save a image to the local file system by setting the imager.destination

                       

                      ex:

                      imager.destination = "url('file://\\Demos\\DamageReport\\Image00" + currentimg + ".jpg')";
                      imager.overwrite = 'TRUE';
                      imager.createFolder = 'TRUE';
                      imager.imagerEvent = 'doImageCaptured(%json)';
                      imager.capture();
                      

                       

                      Then to save that to the database in the form of a DataURL or Base64, the easiest way to do that is:

                      1) Create a canvas object

                      2) Load the canvas with the image

                      3) use the Canvase.toDataURL('image/jpg')

                       

                      ex:

                      var imageObj = new Image();

                      imageObj.src = "image.jpg"; //ex assuming that your app is saving to location of where the app is running from

                      var canvas = document.getElementById("mycanvas");  //assuming you have a canvas object o=in your html called mycanvas
                      var img    = canvas.toDataURL("image/png"); //save this to the dabase this will be your base64 string

                       

                      with the value in IMG you can write it out as a new Image like so:

                      document.write('<img src="'+img+'"/>');


                        • Re: Am I running into a cross domain problem?
                          oscar soza

                          Hi Rob

                           

                          I'm trying to save the image on a directory in a SDCARD of ET1 but I can't get it. I can hear the sound of the capture but i don't get the image in the directory that i assign.

                           

                          I tried this way:

                          pathname = "\\mnt\\sdcard\\Android\\data\\com.motorolasolutions.rhoelements\\CmzIBM\\fotos\\Oscar.jpg";

                          imager.destination = "url('file://" + pathname + "')";

                          imager.destination = pathname;

                          imager.overwrite = 'TRUE';

                          imager.createFolder = 'TRUE';

                          imager.imagerEvent = 'doImageCaptured(%json)';

                          imager.capture();

                           

                          This one too:

                           

                          pathname = "\\mnt\\sdcard\\Android\\data\\com.motorolasolutions.rhoelements\\CmzIBM\\fotos\\Oscar.jpg";

                          imager.destination = pathname;

                          imager.overwrite = 'TRUE';

                          imager.createFolder = 'TRUE';

                          imager.imagerEvent = 'doImageCaptured(%json)';

                          imager.capture();

                           

                          And this one

                           

                          pathname = "\\mnt\\sdcard\\Android\\data\\com.motorolasolutions.rhoelements\\CmzIBM\\fotos\\Oscar.jpg";

                          imager.destination = pathname;

                          imager.capture();

                           

                          Can you help me please?