Generate the Full URL for Uploaded Files on a Server

Generate the Full URL for Uploaded Files on a Server

Most commonly when you save a file in your server you will be using a context name to define the physical location in which the files are stored and also you may be using the same context name for the file paths in your database records, see the following images as examples:





This configuration allow you to shorten the URLs and also hides the important information about physical locations in your server but sometimes you may need retrieve the real URL for the files in order to process specific actions like download a file, to achieve this you can create a Source code objet in Plex that will return you the real path of a specific file, to do this please follow this instructions:

  1. In Plex creates a field called “FilePath” with this configuration
  2. Creates a source code object called “GenerateFileURL” with this configuration
  3. Add the following code to your “GenerateFileURL” source code:

    {

                    com.adcaustin.webclient.IWebApp webApp = (com.adcaustin.webclient.IWebApp)(Object)this.getApp() ;

        javax.servlet.http.HttpServletRequest request = (javax.servlet.http.HttpServletRequest)webApp.getFromUserStorage("javax.servlet.http.HttpServletRequest") ;

                    String fileName = &(1:).toString() ;  

        String path = fileName.replace( "\\", "/") ;

        path = path.replace( "%", "%25" ).replace( "#", "%23" ) ;

        String fileUrl = "http://" + request.getServerName() + ":" + String.valueOf(request.getServerPort()) + request.getContextPath() + "/" +path ;

                    &(2:).fromString( fileUrl ) ;

    }

  4. Call the “GenerateFileURL” source code anytime you need get the real URL for a file, remember this:
    aThe parameter “FilePath” represent your file URL that uses the context name.
    b. 
    The parameter “URL” represent the field that will store the real URL for the file.





    • Related Articles

    • Download File From URL Control Template Manual

      The “DownloadFileFromURL.ctrl” template can be used to download files stored in your server, to implement this template follow these instructions: In Eclipse, copy the “DownloadFileFromURL.ctrl” file into your “Custom Templates” folder In Plex create ...
    • Client/Server Guidelines

      This document is intended to help CM First customers appropriately size CM evolveIT Client and Server hardware and windows configuration for a CM evolveIT installation. A typical CM evolveIT installation would include a Windows server and a CM ...
    • URL for Software and Documentation

      Documents Upgrade Guide Apply New License to MatchPoint Software MatchPoint 7.0 Build 003 (New) Full Installer IBM Components for manual installation System Requirements Updates included 20210521 Update user Password from Menu Solved Webservice PCML ...
    • Open PDF Files in WebClient

      This tutorial describes how to open a PDF file from WebClient by using a custom template. This template uses the panel title as the URL to open the file. To implement this template, follow these steps: In Eclipse, create a custom template file called ...
    • How to generate a license file

      1. Open an administrator command prompt window, and type the following commands:  2. SET DMS_DOMAINS=C:\Program Files (x86)\CMFirst Technologies\cmMetaAnalytics\DMS\Domains  3. PATH %PATH%;C:\Program Files (x86)\CMFirst ...