You are viewing limited content. For full access, please sign in.

Question

Question

Save image to Laserfiche from mobile application

asked on December 22, 2015

Hello,

My team is developing a mobile application that is going to be used when load/unloading trailers to process shipment data.  Part of the process requires that a picture is taken of the Load/Trailer to prevent damage claims.  

I am looking for a way to pass the picture(s) and Metadata to Laserfiche directly.  The images will be saved as JPG files, but I cannot find a way to pass the information directly to Laserfiche.  My thought is to pass the information via ByteArray, but cannot find any code samples to accomplish this.  

 

I have tried to work with the Sample Web API Code (below) provided as part of the Steve's Doors Case Study.  This appears to be saving the image to a Web Server, then Laserfiche is picking up the image from there.  We are trying to bypass the Web Server step and link our Mobile Application directly to Laserfiche through code.  Can anyone provide guidance on how this can be done?  Or steer me in the right direction?  

[WebMethod]
    public string PostToLF(string sPalletID, byte[] Pic1 = null, byte[] Pic2 = null, byte[] Pic3 = null)
    {
        string stemp = "";

        //clear directory
        if (File.Exists(@"c:\temp\pic1.jpg"))
        {
            File.Delete(@"c:\temp\pic1.jpg");
        }
        if (File.Exists(@"c:\temp\pic2.jpg"))
        {
            File.Delete(@"c:\temp\pic2.jpg");
        }
        if (File.Exists(@"c:\temp\pic3.jpg"))
        {
            File.Delete(@"c:\temp\pic3.jpg");
        }
	
	//Save Pictures to disk
        if (Pic1.Length > 100)
        {
            try
            {
                BinaryWriter writer = new BinaryWriter(File.Open(@"c:\temp\pic1.jpg", FileMode.Create));
                writer.Write(Pic1);
                writer.Close();
                writer = null;
                stemp += "Uploaded Image 1" + Environment.NewLine;

            }
            catch (Exception ex)
            {
                stemp += ex.ToString() + Environment.NewLine;
            }
        }

        if (Pic2.Length > 100)
        {
            try
            {
                BinaryWriter writer = new BinaryWriter(File.Open(@"c:\temp\pic2.jpg", FileMode.Create));
                writer.Write(Pic2);
                writer.Close();
                writer = null;
                stemp += "Uploaded Image 2" + Environment.NewLine;

            }
            catch (Exception ex)
            {
                stemp += ex.ToString() + Environment.NewLine;
            }
        }

        if (Pic3.Length > 100)
        {
            try
            {
                BinaryWriter writer = new BinaryWriter(File.Open(@"c:\temp\pic3.jpg", FileMode.Create));
                writer.Write(Pic3);
                writer.Close();
                writer = null;
                stemp += "Uploaded Image 3" + Environment.NewLine;

            }
            catch (Exception ex)
            {
                stemp += ex.ToString() + Environment.NewLine;
            }
        }


        //get SONUM, TLID, CARNUM for this order to store in LF.
        string queryString = "SQL Query Here";       

        SqlConnection connection = new SqlConnection(“SQL Connection String Here”);
        connection.Open();

        SqlCommand command = new SqlCommand(queryString, connection);
        SqlDataAdapter da = new SqlDataAdapter(command);
        DataTable dtResults = new DataTable();
        da.Fill(dtResults);
        da = null;
        command = null;
        connection.Close();
        connection = null;

        string sSONum = "";
        string sTLID = "";
        string sCARNUM = "";
        string sPONUM = "";
        if (dtResults.Rows.Count > 0)
        {
            sSONum = dtResults.Rows[0]["SONUM"].ToString();
            sTLID = dtResults.Rows[0]["TLID"].ToString();
            sCARNUM = dtResults.Rows[0]["CARNUM"].ToString();
            sPONUM = dtResults.Rows[0]["PONUM"].ToString();
        }
        else
        {
            return "ERROR: Invalid PalletID";
        }


        //upload files into laserfiche

        //create a connection to the Laserfiche repository
        RepositoryRegistration myRegistration = new RepositoryRegistration("Laserfiche Server Address", " Laserfiche Repository Name");
        Session mySession = new Session();

        try
        {
            mySession.LogIn("Laserfiche User Name", " Laserfiche Password", myRegistration);

            if (mySession != null)
            {
                //push into laserfiche

                FolderInfo rootFolder;
                rootFolder = Folder.GetFolderInfo(@"Laserfiche Directory", mySession);

                //import selected pictures
                for (int i = 1; i < 4; i++)
                {
                    if (File.Exists(@"c:\temp\pic" + i.ToString() + ".jpg"))
                    {
                        DocumentInfo docInfo = new DocumentInfo(mySession);
                        docInfo.Create(rootFolder, sPalletID + " - Picture " + i.ToString(), "GENERAL", EntryNameOption.AutoRename);
                        docInfo.SetTemplate("PICS");
                        FieldValueCollection myFields = new FieldValueCollection();
                        myFields.Add("Pallet ID", sPalletID);
                        myFields.Add("Truckload ID", sTLID);
                        myFields.Add("Shipping Order Number", sSONum);
                        myFields.Add("CARNUM", sCARNUM);
                        myFields.Add("PONUM", sPONUM);


                        docInfo.SetFieldValues(myFields);
                        docInfo.Save();

                        DocumentImporter myImporter = new DocumentImporter();
                        myImporter.Document = docInfo;
                        myImporter.ImportEdoc("JPG", @"c:\temp\pic" + i.ToString() + ".jpg");
                    }
                }
            }
            else
            {
                stemp = "ERROR: Unable to connect to Laserfiche. \nPlease try again later.";
            }



        }
        catch (Exception exc)
        {
            stemp = "ERROR:" + exc.ToString();
        }
        finally
        {
            if (mySession.LogInTime.Year.ToString() != "1")
            {
                mySession.LogOut();
            }
            mySession = null;
            myRegistration = null;
        }

        return stemp;
    }

Any help is much appreciated!

Cheers,

Nate

0 0

Replies

replied on December 22, 2015

What mobile platform is this for?  Repository Access is available for 32 bit and 64 bit Windows only.

0 0
replied on December 22, 2015

You need some service running on Windows (maybe hosted on IIS) that receives the image and uses RepositoryAccess to store it in Laserfiche (maybe as a document page or blob template field or an image attachment). Your sample code would be part of that service. Even if you would be using a cross-platform mobile framework like Xamarin and C# you cannot use RepositoryAccess from the app directly as RA has not been ported to iOS/Android. Your app would be using an http client to issue the requests to that service. How exactly that request looks like depends on the type of app you are writing (native or web/hybrid).

0 0
replied on December 22, 2015

If storing the image as a doc page works for you (it does not necessarily has to be stored as metadata) the Laserfiche Mobile apps should work out of the box.

It’s worth mentioning that storing images in Laserfiche works best as document pages. Metadata fields are not ideal for storing images – for one thing the size is limited to 64KB which is way below the size of images taken by high resolution cameras of modern phones. Image annotations are also not meant to store large images, the size limit is higher (I believe 512KB) but still much smaller than camera pics.

Another alternative is attaching images to Laserfiche Forms fields which is also supported out of the box in the LFMobile app.

0 0
replied on December 11, 2018

Question from a non-SDK user: Can the SDK perform queries in SQL?

Thanks

0 0
replied on December 11, 2018

Clients are not allowed to make direct SQL queries as that would bypass Laserfiche security.  Is there something you want to do that you can't do through the SDK?

0 0
replied on December 11, 2018

No, I think that answers it. I am not familiar with the SDK, so I am asking for another conversation I was having here. Feel free to chime in!

Thanks

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.