Select to view content in your preferred language

by javascript I can save image from tomcat server but why can't from arcgis server

3249
9
07-22-2011 07:18 AM
MdAziz
by
Emerging Contributor
Hi...
by javascript in IE I can run it and can save image from tomcatserver, the code has given at bellow. But why i can't save image from ArcGIS server using this code??? I have tried many times but I'm failure :confused:

code ::

<script>
function SaveFile(fname){
img.document.execCommand('saveas', null ,fname)
} </script>

<html> <body>
<iframe id="img" src="aziz_pic.jpg" width="600" height="450" scrolling="no" frameborder="0px"> </iframe>
<input name="" value= "Save" type="button" onclick="SaveFile('aziz_pic.jpg')" />
</body>
</html>

please help me to solve this. I want to save map image from arcgis server.
0 Kudos
9 Replies
MdAziz
by
Emerging Contributor
** actually the previous code i have tried before but now I'm trying to use following code.

function exportCensusMap() {
        var params = new esri.layers.ImageParameters();
        params.bbox = map.extent;
        params.width = 500;
        params.height = 400;
        params.format = "png8";
        params.transparent = true;

        baseLayer.exportMapImage(params, function (mapImage) {
            dojo.byId("img").src = mapImage.href;
       var i = dojo.byId("img").src;
       img.document.execCommand('saveas', null ,i)

      });
      }

Really I'm trying to save image from esri server, some one can help me please? I'm new in javascript.

Thanks in advance
0 Kudos
derekswingley1
Deactivated User
Please provide more info on exactly what you're trying to do. Are you trying to get an image from a dynamic map service? Please be specific.
0 Kudos
AxelSchaefer
Emerging Contributor
Hi.

AFAIK, you cannot save files via plain JavaScript. You need a server roundtrip to a webserver (Apache, IIS, Tomcat, etc.). This one will provide you with a download dialog.

Axel
0 Kudos
derekswingley1
Deactivated User
0 Kudos
MdAziz
by
Emerging Contributor
Hi,

Yes, i'm trying to save an image from a dynamic map service. In the code bellow, i can display the image in the frame named img. When i try to save it, i get an error "Access is denied" in internet explorer.


This is the full html code.

[HTML]<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <title>Create Map</title>
    <link rel="stylesheet" type="text/css" href="css/claro.css">
    <script type="text/javascript" src="css/2.3"></script>
    <script type="text/javascript">
      dojo.require("esri.map");
  
      var map, baseLayer, imgsrc;
      function init() {
        map = new esri.Map("map");
  baseLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://10.10.0.72:8399/arcgis/rest/services/landparcellot/MapServer");
        map.addLayer(baseLayer);
      }

      function exportCensusMap() {
        var params = new esri.layers.ImageParameters();
        params.bbox = map.extent;
        params.width = 500;
        params.height = 400;
        params.format = "png8";
        params.transparent = true;

        baseLayer.exportMapImage(params, function (mapImage) {
            dojo.byId("img").src = mapImage.href;
   imgsrc = mapImage.href;
   var t=setTimeout("test()",3000); //set the timer to save the image after 3 seconds to allow the image to be loaded to the frame
   //img.document.execCommand('saveas', null, mapImage.href);
        });
      }
  
   function test(){
  img.document.execCommand('saveas', null, imgsrc); //here is where the error prompts
   }
      dojo.addOnLoad(init);
    </script>
  </head>

  <body class="tundra">
    Click <input type="button" value="Export Map" onclick="exportCensusMap();" /> to display the map for the current map extent.
    <table>
        <tr>
            <td>
                <div id="map" style="width:500px; height:400px; border:1px solid #000;"></div>
            </td>
            <td valign="top">
                <div id="imageDiv" style="border: 1px solid #000;">
                    <iframe id="img" src="" frameborder="0px"> </iframe>
                 </div>
            </td>
        </tr>
    </table>
  </body>
</html>[/HTML]

I can use the code (img.document.execCommand('saveas', null, imgsrc); ) to save an image if the image is in the same tomcat directory. But the exportMapImage function will generate the image and save it in the arcgis server machine. And yes, we use tomcat web server. Any advice? Please let me know if you need any information.
0 Kudos
MdAziz
by
Emerging Contributor
Hi
every one, really I need the solution, so can any one help me out of the problem please?? Really it's urgent for me .... Thanks in advance.
0 Kudos
AxelSchaefer
Emerging Contributor
If "img.document.execCommand('saveas', null, imgsrc);" throws an exception, there has to be an error with that function.

http://lmgtfy.com/?q=execCommand+saveas

Solution: "execCommand" seems to be a sloppy thing and only supported by IE. You have to check that and search for a hack or implement your functionality in a different way, for example with a server roundtrip (PHP, SOAP, REST, anything else), because a server can provide a download dialog in the TCP/IP stack. Or you experiment with HTML 5 like Derek mentioned.

I hope, that clarifies what you have to do.
0 Kudos
MdAziz
by
Emerging Contributor
Thanks axxl & to others also.
But Axxl  what have u said i have done before u said but it doesn't work. And i can't save map as an image , but i can save the html page. Axxl it's not a normal image, it's map where has many layers combination, may be that's why it different. However thanks again, because I see here has many helpful hands who are really willing to help other. :cool:
0 Kudos
HemingZhu
Frequent Contributor
Thanks axxl & to others also.
But Axxl  what have u said i have done before u said but it doesn't work. And i can't save map as an image , but i can save the html page. Axxl it's not a normal image, it's map where has many layers combination, may be that's why it different. However thanks again, because I see here has many helpful hands who are really willing to help other. :cool:


exportMapImage will save the image to \\arcgisserver\output folder, usually you can get its source by using MapImage.href (using a hyperlink...). However things might get a little complicated if you are using a reverse proxy or java web server, you have to make sure the your MapImage.href is accessable by your ArcGISWebService account.
0 Kudos