{"id":1128,"date":"2008-07-09T03:45:24","date_gmt":"2008-07-09T08:45:24","guid":{"rendered":"http:\/\/www.mrc-productivity.com\/docs\/?page_id=1128"},"modified":"2024-11-22T15:10:34","modified_gmt":"2024-11-22T21:10:34","slug":"upload-files-to-server-via-web-2-0-maintenance-applications","status":"publish","type":"ht_kb","link":"https:\/\/www.mrc-productivity.com\/docs\/knowledge-base\/upload-files-to-server-via-web-2-0-maintenance-applications","title":{"rendered":"Upload Files to Server"},"content":{"rendered":"\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\"><em>Click <a href=\"https:\/\/www.mrc-productivity.com\/legacy\/maint\/upload-files-to-server-via-web-2-0-maintenance-applications\">here<\/a> to access legacy documentation for this feature.<\/em><\/p>\n\n\n\n<p>One feature of Maintainers is to allow the uploading of files from your client machine to the server. This feature is unique in the fact that it will also add a record to the database, as well as upload the specific file to the server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"getting-started\">Getting Started<\/h2>\n\n\n\n<p>To begin, create a maintenance application as you normally would. In &#8220;Field Settings&#8221;, change the dropdown box from &#8220;Basic field attributes&#8221; to &#8220;Form input attributes.&#8221; <\/p>\n\n\n\n<p>Find the field that will serve as the <strong>File Name<\/strong> for the uploaded file. In the &#8220;User Def&#8221; column, select the &#8220;U&#8221;. This will tell m-Power to create an upload button next to this field and when the record is written to the table, write the File Name to this field.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/docs\/vue-images\/uploading1.jpg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Figure 1 &#8211; Setting a field as an upload field in Field Settings.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"app-properties\">App Properties<\/h2>\n\n\n\n<p>Before running the application, let&#8217;s look at the application properties for this program. After you scroll to the bottom, you will see these three options:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/docs\/vue-images\/uploading2.jpg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Figure 2 &#8211; Various application properties associated with the file upload functionality.<\/figcaption><\/figure>\n\n\n\n<p><strong>File Upload Directory<\/strong> &#8212; The location on the m-Power server where this file will be uploaded. If the folder does not exist, it will be created.<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">While you must pick a valid drive, this property supports two substitutions for dynamic uploading. First, you can use <code>${mpower}<\/code> to automatically select the m-Power folder, which is useful for deployment between development and production. Second, you can use <code>${FIELD}<\/code> where FIELD is the name of a field, which can be used to upload a file to a directory dependent upon some form value your end user selects.<\/p>\n\n\n\n<p><strong>File Upload Max Size<\/strong> &#8212; The maximum size, in megabytes, that a file can be in order to be uploaded. If a file is too large, the user will see an error at runtime that they must pick a smaller file.<\/p>\n\n\n\n<p><strong>File Upload Auto Rename<\/strong> &#8212; Allows you to control the behavior when a file of the same name already exists in the upload directory. You can either choose to have m-Power auto-rename the file (so file.txt would become file(1).txt) or you can automatically overwrite the existing file.<\/p>\n\n\n\n<p>Make any necessary changes and click &#8220;OK&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"runtime-usage\">Runtime Usage<\/h2>\n\n\n\n<p>When I run my application, I see something like this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/docs\/vue-images\/uploading3.jpg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Figure 3 &#8211; A single row maintainer with an upload field called &#8220;Attachment&#8221;.<\/figcaption><\/figure>\n\n\n\n<p>Notice the &#8220;Browse&#8221; button in the Attachment input. Clicking on &#8220;Browse&#8221; brings up a view of my local machine. After I select a file, the location will be inserted.<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-alert\">The upload feature is designed only to add files. This feature is not meant to remove files or modify files in any way, other than already discussed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"error-checking\"><strong>Error Checking<\/strong><\/h2>\n\n\n\n<p>Below is a list of the common error checking that m-Power will do to ensure that the proper information is being uploaded:<\/p>\n\n\n\n<p>If the file name is too long, this error is displayed:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/docs\/vue-images\/uploading4.jpg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Figure 4 &#8211; If a user tries to upload a filename too long, the above error is displayed.<\/figcaption><\/figure>\n\n\n\n<p>If a file exceeds the maximum size, this error is displayed:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/docs\/vue-images\/uploading6.jpg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Figure 5 &#8211; If a user tries to upload a file size too large, the above error is displayed.<\/figcaption><\/figure>\n\n\n\n<p><strong>Editor&#8217;s Note:<\/strong> The Maximum Size was changed in this example for practicality purposes. The default size is 100 MB.<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-alert\">The number of characters in the file name can not exceed the length of the File Name field. For instance, if I want to upload the file &#8220;Damaged_goods.jpg&#8221; to a 15 alpha field, it would be rejected, as &#8220;Damaged_goods.jpg&#8221; is 17 characters long.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Downloading files from the server<\/h2>\n\n\n\n<p>By default, the upload feature will not automatically include the ability to view or download any uploaded files. However, a developer may use m-Painter&#8217;s smartlink functionality to add a hyperlink to their uploaded file, thus allowing the user to view the uploaded view. <\/p>\n\n\n\n<p>For how to do this, please see <a href=\"https:\/\/www.mrc-productivity.com\/docs\/knowledge-base\/downloading-files\" data-type=\"ht_kb\" data-id=\"14341\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"secureFile\"><strong>Secure File Upload\/Download<\/strong><\/h2>\n\n\n\n<p>The above setup is the default method of uploading a file through an m-Power maintainer. Using the above method, the uploaded file is potentially available to anyone who knows the full URL of the file&#8217;s location. If there is a need to keep files secure behind m-Power\/Tomcat security, please follow the below instructions.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h3 class=\"wp-block-heading\" id=\"configuration\">Configuration<\/h3>\n\n\n\n<p>The required setup is similar for the maintainer to upload a file:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set the upload field to &#8216;U&#8217; in the Field Settings -&gt; Form Input Attributes. <\/li>\n\n\n\n<li>Set the App Property -&gt; File Upload Directory to a valid directory. The secured directory of your choosing must be outside of the \/mrcjava context. For example: <code>C:\\SecureUpload<\/code> is a valid directory.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"secure-file-download\">Secure File Download<\/h3>\n\n\n\n<p>To download a secure file, users will still click a link to access and download the file to their local PC. However, with this setup the browser will no longer display the file&#8217;s location via the URL. Instead, a developer will assign an &#8220;output queue&#8221; from the m-Power Interface Messaging and Scheduled Task module to &#8220;hide&#8221; the location to the runtime users. <\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h4 class=\"wp-block-heading\" id=\"output-queue-setup\">Output Queue Setup<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to Admin -&gt; Messaging and Scheduled Tasks -&gt; Output Folders.<\/li>\n\n\n\n<li>Click &#8220;Add Output Folder&#8221;.<\/li>\n\n\n\n<li>Specify a folder name and specify the location of the secured directory as set in the maintainer&#8217;s app properties (e.g. <code>C:\\SecureUpload<\/code>).<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.mrc-productivity.com\/docs\/vue-images\/outputQueue1.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Figure 6 &#8211; Setting up an Output Folder.<\/figcaption><\/figure>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\"><strong>Important<\/strong> &#8211; If you are uploading to a dynamic directory in within your maintainer&#8217;s &#8220;File Upload Directory&#8221; property (e.g. <code>C:\\SecureUpload\\<strong>${FIELD}<\/strong><\/code>), then this same field substitution needs to be used within the folder path when setting up your Output Folder:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"\/docs\/vue-images\/outputQueue2.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Figure 7 &#8211; Setting up an Output Folder with a dynamic field value.<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"download-link-setup\">Download Link Setup<\/h4>\n\n\n\n<p>m-Power Developers will build the link to access the secure file in m-Painter. Highlight the upload file fieldname in m-Painter -&gt; Right-click -&gt; Insert\/Edit link. Use the syntax below to construct the appropriate link URL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DATADICTIONARY.M12345s?downloadbinary=1&amp;filefield=SFILENAME&amp;queue=SecureUp\nload&amp;slnk=1&amp;KEYFIELD=${row.KEYFIELD?url}&amp;FIELD=${row.FIELD?url}<\/code><\/pre>\n\n\n\n<p>See the explanation of the URL parameters below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>DATADICTIONARY.M12345s<\/code><\/strong>: This is the maintainer application (or it can be another app secured against Row Level Security. See <a href=\"#secure-file-row-level-security\" data-type=\"internal\" data-id=\"#secure-file-row-level-security\">below <\/a>for steps on implementing Row Level Security). Replace these values with your appropriate dictionary and application number.<\/li>\n\n\n\n<li><strong><code>downloadbinary=1<\/code><\/strong>: Specifies the secure file logic should be called to return a file, not call an application.<\/li>\n\n\n\n<li><strong><code>filefield=SFFILENAME<\/code><\/strong>: Tells m-Power what field to look at to find the name of the file to download. Please replace SFFILENAME with your actual field.<\/li>\n\n\n\n<li><strong><code>queue=SecureUpload<\/code>:<\/strong> Tells m-Power to get the file from the secure location created in the Messaging and Scheduled Tasks Output folder. Replace SecureUpload with whatever Folder Identifier Name was chosen in the <a href=\"#output-queue-setup\" data-type=\"internal\" data-id=\"#output-queue-setup\">Output Queue Setup<\/a> section.<\/li>\n\n\n\n<li><strong><code>slnk=1<\/code><\/strong>: Tells m-Power to only grab data based on the the key passed.<\/li>\n\n\n\n<li><code><strong>KEYFIELD=${row.KEYFIELD?url}<\/strong><\/code> &#8211;  Tells m-Power, just like in a normal maintainer app, to only work with a given record. Please replace KEY with the actual key of your app. If you have more than one, please pass all as separate parameters (i.e.<code>KEYFIELD1=${row.KEYFIELD1?url}&amp;KEYFIELD2=${row.KEYFIELD?url}<\/code>).<\/li>\n\n\n\n<li><code><strong>FIELD=${row.FIELD?url}<\/strong><\/code> &#8211; Optional. Only required if using a field name within the Output Folder path, as shown in Figure 7.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"rowSec\">Secure File Row Level Security<\/h4>\n\n\n\n<p>An added benefit of securing these files behind m-Power security is the ability to also introduce <a rel=\"noreferrer noopener\" href=\"\/docs\/knowledge-base\/row-level-security\" data-type=\"URL\" data-id=\"\/docs\/knowledge-base\/row-level-security\" target=\"_blank\">Row Level Security<\/a> as an additional security level. This will allow a developer to control individual user access to a file based on the key(s) of the record containing the uploaded file name. <\/p>\n\n\n\n<p>Two applications will be needed for this setup:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Row Level Security retrieval will be needed to serve as the security agent controlling user access to the record. Follow the <a rel=\"noreferrer noopener\" href=\"\/docs\/knowledge-base\/row-level-security\" data-type=\"URL\" data-id=\"\/docs\/knowledge-base\/row-level-security\" target=\"_blank\">documentation steps<\/a> to secure against the key value(s).<\/li>\n\n\n\n<li>Single Row Retrieval to serve as the application to hold the row level security agent. This is the application that will be used in the <a href=\"#download-link-setup\">download link created above<\/a> instead of the maintainer. <\/li>\n<\/ol>\n\n\n\n<p>When the download link is clicked by an end user, the parent application will pass the key(s) to the retrieval from step 2. Row level security will be invoked to determine if the user should have access to the record and in turn, the secured file. If row level security allows the user to access the record, the secure file will be downloaded to the user&#8217;s local PC. If the user does not have access to the record, the file will not download.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This document discusses how to use a maintainer applications in order to upload fie attachments to the m-Power server. <\/p>\n","protected":false},"author":1,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[252],"ht-kb-tag":[],"class_list":["post-1128","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-maintainer"],"_links":{"self":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/comments?post=1128"}],"version-history":[{"count":40,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1128\/revisions"}],"predecessor-version":[{"id":14393,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb\/1128\/revisions\/14393"}],"wp:attachment":[{"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/media?parent=1128"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-category?post=1128"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.mrc-productivity.com\/docs\/wp-json\/wp\/v2\/ht-kb-tag?post=1128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}