Setting Upload directory

27 May '14, 11:48 AM
18,766 Views
No Forum Badges

Hi,

More issues with uploading files. I am implementing the functionality to store a file (image) locally rather than in the database. I want to create a link to the image so that whnen it is requested it is not making a db call.

Initially the upload was going to uploads/ent/<number> but the ent/<number> bit changed and seemed a bit random to work with. The only path information I gave upload/ and java/webratio was adding in the rest. I then changed the script to create a file explicitely but now I get an error that the path does not exist. When I pass out the full path of the file I am trying to create I see it is trying to create the file in the tomcat/bin folder.

How can I set the upload directory just to be upload? Or alternatively is there a way I can use the ${webapp_loc} and ${projectname} (I think they are correct) Webratio variables inside a script? These would let me create the full path correctly?

Thanks,

Paul

 
x 0
Follow
Answer Answer at this question and get points!
Forum Starter - Level 2

Hi,

To achieve this, you must edit the ${webapp_loc}//WebContent/WEB-INF/conf/RTXConfig.properties

Within this file, it is a property called "uploadDirectory=" which is comment (with #). Uncomment this and set the directory designed to store uploaded files. This path must be relative to the work directory. If you want to set and absoluth path, uncomment the next property ("uploadDirectoryIsAbsolute") and set it to true.

Good luck

 
x 1
No Forum Badges

Thanks. This resolved the issue. I think the fact I missed was that the application runs from tomcat/bin, not from the application directory as I thought. Som making the path ralative from tomcat/bin works.

I guess the only thing I need to check is that the path structure will be the same when the application is deployed as opposed to running unde eclipse. I did try using a variable in RTXConfig.properties but this only printed out the variable name. Is it not possible to use variables in this file? If it is, what is the syntax?

Thanks,

Paul

 
x 0
Forum Expert - Level 5

Hi,

Test with ${RTXConfig.properties}

 
x 0
Forum Starter - Level 2

Hi,

 

As far as I understood, you want to be sure that your relative upload path works is managed at the beginning of generation process? If this is true you can try the following approach

In Webratio, in "Webratio Explorer" window create the same structure that you have in webapps folder.

So, under the WR project create WebContent/WEB-INF/conf/ folder. Copy the RTXConfig.properties from the previous generated code (${webapp_loc}/WebContent/WEB-INF/conf/RTXConfig.properties). Now you can modify this file inside the project and when you will deploy you'll have the same properties/values defined in it. 

Also, in order to read/write variables inside this RTXConfig.properties file, I think you can use the java to achieve this task.

 

To read variables inside RTXConfig.properties :

 

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
 
public class App{
  public static void readProperties(String path) {
  
        // path = "pathToRTX/RTXConfig.properties"
	Properties prop = new Properties();
	InputStream input = null;
 
	try {
 
		input = new FileInputStream(path);
 
		// load RTX Config
		prop.load(input);
 
		// get the property value and print it out
		System.out.println(prop.getProperty("uploadDirectory"));
		System.out.println(prop.getProperty("uploadDirectoryIsAbsolute"));
 
	} catch (IOException ex) {
		ex.printStackTrace();
	} finally {
		if (input != null) {
			try {
				input.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
 
  }
}

 

To write variables inside RTXConfig.properties you can use the following method:

 

 public static void writeProperty(String pathOfFile, String property, String value) {	
// path = "pathToRTX/RTXConfig.properties"
        Properties prop = new Properties();
	OutputStream output = null;
 
	try {
 
		output = new FileOutputStream("path);
 
		// set the properties value
		prop.setProperty(property, value);
		//prop.setProperty("uploadDirectory", "/relativePath");
		// save properties to project root folder
		prop.store(output, null);
 
	} catch (IOException io) {
		io.printStackTrace();
	} finally {
		if (output != null) {
			try {
				output.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
 
  }
}

 

Hope this will help you

 
x 0
Answer at this question and get points!

Related questions

add html Add logging capability to a Groovy script (unit) Add select all to Checkable List Ajax and FCK Editor (WebRatio 5.x) AJAX events problem to external JavaScript Ajax onchange and jQuery 2.x (with migrate plugin) incompatible Ajax on change selection field and modify units Autocomplete template Automatic date in form Automatic file upload BPMN: URL field ckeditor - change directory for the browser Clean a form Como crear cambio de contraseƱa Como tener dos botones juntos en un formulario independientes de una accion? Como usar la funciĆ³n autocomplete en un field Compare with the current time Content module page variable won't assign. Convert selector component result to single value coupled mandatory fields Criptare dati sensibili nel database Cryptic error when submitting a form Data flow from a page which is not visible anymore Disabilitare campi durante evento AJAX Drop down menu question Dudas sobre modelado(Data Flow,Forms y Operation Create) Dynamic attribute/field names. Possible? Dynamic instantiation of fields on a page for any Class type Empty record mistakenly saved entry form logic. Entry Unit - Default field timestamp Entry Unity, Field Date Type Error Execute truncate sql query Field as link soruce file analysis then update MySQL database Form element Form template Get size of Multi Form with Pictures Object Array Getting the absolute path of a RTXBLOBData Groovy and Database Groovy script numer after an error Hide form until a flow is triggered Hiding form components based on page conditions Hierarchy component How can I add a credit card payment gateway or integrate paypal in my web app logic? How can i add html into a page? how can i open a pdf file using download dialog How I can receive the primary key value after adding into database from OK Port. How to calculate dates between start and end point? How to redirect to the correct site view after a successful login attempt How to Retreive data from Multi Selection Field Array Importing JAR Libraries into Script Unit Importing jar library input mask JAR importing Merge the result of 2 (or more) flows [MOBILE] Script doesn't work! Modify generated code / inject own HTML, Javascript code into existing generted code. Multi Entry Unit: How to forward only checked rows? Multi-Image Upload Multiple forms on one page. HTML5 input attributes. Possible? (2 questions) multi selections field problem Multi Selects didn't work in update page Prelevare la chiave del record da una Selection Field in una Multiple Form Problem saving multi selection from input Progress bar when uploading big file(s) in a form? Pulire URL Redirecting users to another site view Resize fields script component Script eseguito alla User Login Script Unit e Mysql ScritpUnit and JSON data Search by Selector component does not work selection fields on cascade Select multiple files for upload Showing items that have a relation with an entity Shuffling Script Slot in Selection Field Standard confirm dialog replacement Unable to execute the script java.lang.NullPointerException Update fields based on selection of other fields Updating attributes of an entity upload file and the move it to other location upload file html Uppercase Uso de la componente chart de webRatio Validacion validation fields Value Length (Min) fails to validate when field is empty? WebRatio 6.1.2: Groovy Version / Versione Groovy WebRation - Create Navigation diagram What are the new features of WebRatio 6.1? which of these three models is closer to webratio/ifml way of creating web applications