Zum Hauptinhalt gehen

Reports with attachment photos?

Kommentare

4 Kommentare

  • Jostein Svegården

    I have exactly the same question these days. Including images stored in a virtual directory on our web server has worked well for us, but now we want to create a selection report template where images are fetched from each feature's attachments. I cannot see that this is documented anywhere, and would like to know if others have done this and how.

    So far, I have looked at the REST url to each attachment to try to generate the report image from that. It contains layer-ID, Feature-ID (objectid) and Attachment-ID. Layer-ID is from the map service, Featue-ID can be read from the attribute table, but Attachment-ID seems not to be logically connected to anything. So what I'm trying now, is to make code that reads the JSON-representation of the features attachmentinfos to get the attachment's ID so I can build a complete URL to the images. Hopefully, I will be able to create images in my reports with this URL as source. 

    If anyone has input regarding this, please share!

    Jostein

    0
  • Permanently deleted user

    Hi Jostein & Peter,

    I have done this, however my solution only attaches the first attachement found per feature (if you have multiple attachments per feature, this same process could probably be used, but taken further). It was a mult-step process, but not entirely difficult. We started by created a script that appends the attatchment ID as an attribute of the featureclass. Then in the report, you can append that attribute to the attachment rest url. The big question is... is your service secured? If so, you need to do some C# to generate a token then apply that token to the attachment rest url as well. I can provide some script if desired.

    0
  • Jostein Svegården

    Thanks, Peter!

    I have thought of that as an option, to add attachment IDs to the feature attribute table. However, I wanted to find a solution without having to alter the database schema of the feature class, so I'm still exploring this attachmentinfos JSON approach.

    I would appreciate getting your code for generating token. I'm currently working against an unsecured service, but I will need to secure it later.

    Jostein

    0
  • Permanently deleted user

    Hi Jostein,

    Here is the code I used to generate a token, reference the attachment name attribute and build a url string that populates an image box on the report.  

     

    using System;

     

    using System.Security.Cryptography;

     

    using System.Text;

     

    using System.Drawing;

     

    using System.IO;

     

    using System.Net;

     

    using System.Net.Sockets;

    bool backColor = true;

     

    public void detail_Format()

     

    {

     

    string tokenServiceUrl = "https://yourserver.com/arcgis/tokens";

     

    UriBuilder uriBuilder = new UriBuilder(tokenServiceUrl);

     

    uriBuilder.Query = "request=getToken&username=yourusername&password=yourpassword";

     

     

     

    System.Net.WebRequest request = System.Net.WebRequest.Create(uriBuilder.Uri);

     

    string myToken = null;

     

    string errorMsg = null;

    try

     

    {

     

        System.Net.WebResponse response = request.GetResponse();

     

        System.IO.Stream responseStream = response.GetResponseStream();

     

        System.IO.StreamReader readStream = new System.IO.StreamReader(responseStream);

     

        myToken = readStream.ReadToEnd();

     

    }

     

    catch (System.Net.WebException ex)

     

    {

    }

     

    //Get the value of the feature from the invisible textbox control

     

    string fieldValue = ((TextBox)rpt.Sections["detail"].Controls["Attach1"]).Value.ToString();

      //Put the value of the feature in the url to the image

     

    string url = string.Format("https://yourserver.com/arcgis/rest/services/yourservice/MapServer/0/0/attachments/{0}", fieldValue);

     

    string url2 = url + "?token="+myToken;

     

     // An inline function to download a URL and make it into a System.Drawing.Image

     

     Image image = new Func<Bitmap>(() =>

     

        {

     

            try

     

            {

     

                using (WebClient downloader = new WebClient())

     

                {

     

                    return new Bitmap(downloader.OpenRead(url2));

     

                }

     

            }

     

            catch (Exception exception)

     

            {

     

       // Deal with it

     

       throw exception;

     

            }

     

        })();

    ((Picture)rpt.Sections["detail"].Controls["Picture1"]).Image = image;

    }

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.