The Proper Way to Attach Files in K2 InfoPath processes

I recently encountered a situation with a customer where they used InfoPath processes in their environment and I noted that they had a large growth in their K2ServerLog database even though the number of process instances was relatively small.

Now this was puzzling until I did the math here.

e.g. 2000 form instances.  Each form has on average roughly 200KB attachments per form.  The process had a couple of approval stages and has about 2-3 slots per stage.  Let's assume a figure of 7 slots here.  Including the process instance data, this would result in 8 copies of the form data.

Also note the following:

  1. The InfoPath client event makes a copy of the InfoPath document per slot
  2. InfoPath file attachments need to be base64 encoded.  This roughly multiplies the attachment size by 1.37 times.

This leads to 2000 X 200KB X 1.37 X 8 = 4.18GB of data.

Now this is a hefty size to manage for just 2000 instances (and it just multiplies as the process gets more complex and the number of instances grow over time).

If you are interested in finding out the table usage in your own K2 environment, you can run this following useful command on your K2ServerLog database.

     EXEC sp_MSforeachtable @command1=”EXEC sp_spaceused ‘?’”

So from an InfoPath standpoint, putting in file attachments to the form is quite bad for storage purposes.  Now there is a good workaround that involves SmartObjects.  Basically the idea is to detach the file data from the form and store the attachment in a SharePoint document library.  Once this is done, you can basically store only the document URL link into the InfoPath form.

Eric has a nice video of how this is done.  It even has a sample form with the necessary rules required.  However, it doesn't show you how to handle multiple attachments and how the initial configuration is done (which might be confusing for newbies).

I have created a document which shows how all this is done (with explanations) from the ground up.  In conjunction with Eric's video, I hope this helps anybody out there who is looking at implementing this solution.

Enjoy!


Posted Tue, Nov 3 2009 6:05 PM by johnny

Comments

NicoH wrote re: The Proper Way to Attach Files in K2 InfoPath processes
on Tue, Dec 1 2009 5:11 AM

Thanks Johnny, this helped me a lot, especially to better understand how you can use smartObjects and how it's integration with InfoPath works.

johnny wrote re: The Proper Way to Attach Files in K2 InfoPath processes
on Tue, Dec 1 2009 6:14 PM

No worries.  Glad that you find this useful.

arduk wrote re: The Proper Way to Attach Files in K2 InfoPath processes
on Tue, Dec 8 2009 3:34 PM

Hi Johnny - great doc that you have attached - very helpful for a newbie to smart objects like me!

A quick(?) question in regard to this - is it possible to change the name of a file when it is uploaded - I have run into this a couple of times, as I would like to give files a unique id number as the file name - this ensures that there are no conflicts with file names etc. This is not just for conflicts of file names that are being uploaded from a single form, but also for files that may be uploaded in different process instances.

I see that you have mentioned "Handling Duplicate Filenames" as one of the things that needs to be addressed if this is to be a full fledged application - is there any chance of you expanding on how you would do this?

If it is not possible to change the filename when it is uploaded, is there some other method I should use in order to achieve this?

Thanks again for the great doc!

johnny wrote re: The Proper Way to Attach Files in K2 InfoPath processes
on Thu, Dec 10 2009 9:52 PM

I haven't thought about it in detail yet but perhaps one thought it to move the attachments into unique folders.  However, I haven't tested this approach out yet so I can't tell if this will work.

If anybody has a creative solution, feel free to contribute their ideas here.

arduk wrote re: The Proper Way to Attach Files in K2 InfoPath processes
on Mon, Dec 14 2009 6:18 PM

Hi Johnny,

Thanks for the response.

I guess I am back to a custom webservice to achieve this....a shame, as the smart object solution appears as if it would have been very simple to set up....maybe the next version will be able to do it???

Thanks again for getting back to me.

johnny wrote re: The Proper Way to Attach Files in K2 InfoPath processes
on Mon, Dec 14 2009 7:35 PM

Actually from doing a bit of testing, it seems that you can specify the folder that you want to upload to.

This is done by modifying the "Folder_K2_ServiceDefined" Input property of the SmartObject Create call.

However, the caveat is that you need to create the folder first before you can upload to it (otherwise you get an error).

Which at this point still means that you need to call a web service to do this.  There's a code references here if you want to see how to create a folder using the SDK.  www.k2distillery.com/.../custom-sharepoint-web-service-upload.html

In the meantime, I am going to log an enhancement to get the Create call to automatically create the folder.

arduk wrote re: The Proper Way to Attach Files in K2 InfoPath processes
on Sun, Jan 3 2010 10:00 PM

cool - thanks for the info - I will have another look at it next time....

perhaps a simpler enhancement would be to have the ability to specify the file name that you want it saved as?

johnny wrote re: The Proper Way to Attach Files in K2 InfoPath processes
on Sun, Jan 3 2010 10:52 PM

I believe I already logged this for enhancement.  Hopefully this will come in at a later date in one of the service packs.