upload file and the move it to other location

22 Sep '11, 04:52 PM
87,262 Views
No Forum Badges

Hello,

I need to upload a file to my server, and then i need to move this uploaded file to another directory and change the name of it.

 
x 1
Follow
Answer Answer at this question and get points!
Forum Expert - Level 8

The solution I gave you writes in the database the path to the file, but the file is stored on the file system in the specific folder you set.

If this is not what you want, can you make an example? If you just store the file on the file system, you wont' be able to retrieve the file in the Web application using the standard units.

In any case, to do this you have to model a Script Unit that stores the file where you want. You can refer to the official WIKI (Getting started with the Script unit). In the Script Unit you have to write down the Java code necessary in order to save the file in a specific position.

   
x 0
Forum Expert - Level 8

Hi,

you can model in the Data Model an attribute of type BLOB inside an Entity. In the Properties View of the attribute you can set a specific Upload Path. This means that when you upload a file, it will be saved in the folder "upload/images/photogallery". The upload folder is located by default inside the webapps folder of the Web application.

alt text

You can change this default and choose a folder outside the webapps one to store files. This can be done configuring the RTXConfig.properties file. This file can be accessed in this way:

  • go to the WebRatio Explorer
  • right click on the Web Project
  • choose the option WebRatio -> Edit RTXConfig.properties

You have to change the uploadDirectory writing an absolute path and then the uploadDirectoryIsAbsolute setting it to "true". In this way you can store files in a specific folder on the file system of the server. For further information about the RTXConfig.properties file you can refer to this article on the WebRatio Official WIKI.

Finally, to change the name of the uploaded file with a custom one, you can model an Entry Unit having two fields:

  • one for the file to be uploaded (that will be a BLOB field)
  • one for renaming the file (if you want the user to choose the new name)

Then, you place a Create Unit over the Entity containing the BLOB attribute. On the coupling of the link connecting the Entry Unit with the Create Unit you will find two couplings available for the BLOB attribute, one is the file itself, the other is the name to assign to the file once it's uploaded.

 
x 1
No Forum Badges

You should first decide whether you need to have the file mapped to an entity (and therefore accessible via standard entity-based units) or not.

If you don't want to permanently store the file on DB but still would like to map it to an entity, a solution could be creating an ad-hoc entity with Duration set to volatile (session scope)/volatile (application scope). However, keep in mind that this will last until the user session expires or the application is restarted.

On the other end, if you don't want to map a BLOB property but just need to upload a file, you can use a Script Unit like suggested by michela.

  • Add an Entry Unit with a Field of the blob type to a Page. This will be yout "upload" form.
  • Create a Script Unit containing the following code.
#input RTXBLOBData file, String path
import org.apache.commons.io.IOUtils

def output = null, input = null;
try {
    output = new FileOutputStream(path)
    input = file.openFileInputStream()
    IOUtils.copy(input, output)
} finally {
    IOUtils.closeQuietly(input)
    IOUtils.closeQuietly(output)
}
  • Create a Link from the Entry Unit to the Script Unit (the "upload" link), couple the blob Field to the script file input and pass the path to copy to in the path script input.

Groovy scripts and the RTXBLOBData interface are explained in the WebRatio Wiki. How to deal with BLOBs.

 
x 1
No Forum Badges

Try make it using filejam upload. Its good way for transfer files

 
x 0
Answer at this question and get points!

Related questions

502 proxy error-generate and run add html Adding and deleting from the database Add logging capability to a Groovy script (unit) Add select all to Checkable List Agregar boton de cambio de contraseña en el login 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 Alimentar graficas con base de datos Atributos Condicionales heredados Attribute comparison in a selector unit Autocomplete template Automatic date in form Automatic file upload [beginner] - How to store and browse data collected with BPM app? BPMN: URL field Business object data Cancellare campi e tabelle dal database Cannot add a Database in the Domain Model Cannot connect to MySQL Cannot insert an entity in the database Cannot invoke method selectSingleNode() on null object Can't generate and run database or start tomcat server! Change uplod directory and protect anauthorized access to files ckeditor - change directory for the browser Clean a form Como crear cambio de contraseña Como mostrar una imagen en una lista o en la componente detalles? Como recuperar todos los atributos de una relacion N:N y insertar registros? 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 Conexion a Oracle 12g Connection refused. connect to Cloud Content module page variable won't assign. Convert data in a Calculated attribute Convert selector component result to single value coupled mandatory fields Creación DB Apache Derby - Modelado BPMN Criptare dati sensibili nel database Cryptic error when submitting a form Database connection, Host and Port number Database password encrypting Database properties Database resource consumption Database Tables Creation After Remote Deploy Data flow from a page which is not visible anymore DB in Data Service Project Deploy in Cloud Amazon Beanstalk with Postgres Disabilitare campi durante evento AJAX Drop down menu question Dudas sobre modelado(Data Flow,Forms y Operation Create) Dynamic attribute/field names. Possible? Dynamic data type 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 Error updating metadata process EverLasting error "The TCP/IP connection to the host has failed. Connection refused" Execute truncate sql query Field as link soruce file analysis then update MySQL database Find Model Problemas Foriegn key relationship Form element Form template Generate and run locally on webratio professional edition. Get size of Multi Form with Pictures Object Array getting data from database Getting the absolute path of a RTXBLOBData Groovy and Database Groovy script numer after an error Guardar Saltos de LINEA Hide a form if condition if true 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 import a view in the Domain Model as an attribute of an Entity? how can i open a pdf file using download dialog How database or datamodel migration? How I can receive the primary key value after adding into database from OK Port. How to block empty string in Database How to calculate dates between start and end point? How to disble derby database? How to fix Network error(status 0) How to redirect to the correct site view after a successful login attempt How to Retreive data from Multi Selection Field Array How to run web app with authentication service How to show certain values derived from relations in the domain model? I can't run any application with WebRatio (Table/View 'APP.POST' does not exist) Image in List field Importing JAR Libraries into Script Unit Importing jar library input mask Insert data into database Is it possible to create a derived relationship between databases? JAR importing JDBC4 Postgresql Driver JDBC connection with mysql on mac Job not start correctly Mapping database of the entity '...' is unspecified Merge the result of 2 (or more) flows [MOBILE] Can't synchronize domain model with beck end DB [MOBILE] Script doesn't work! Modify generated code / inject own HTML, Javascript code into existing generted code. Mostrar datos de diferentes tablas/ show dates from diferentes entities MS SQL server jdbc file 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 MySQL Driver jdbc No Apache Derby driver found No Database on Cloud account No database on my cloud account Passing JSON Object to Model Personalizzare lo stile di un progetto PostgreSQL Predefined values in database Prelevare la chiave del record da una Selection Field in una Multiple Form Problem accessing MySQL with WebRatio 6 Problema Grafo da una lista gerarchica Problema ¨HTTP Status 404" Problemas con el Operations View Delete Problem saving multi selection from input Problems to connect Sql Server DB from Webratio Problems with Database Metadata Problem with fields with accents used in attribute condition Problem with query unit! Problem with stored procedure Problem with the deletion of more than 50.000 records in a table Progress bar when uploading big file(s) in a form? publish web service for storing information in PostgreSQL DB following XSD Resource Pulire URL query a database Redirecting users to another site view Refresh and Synchronize DB Problems Relaciones Removing the User-Group-Module tagles Resize fields Retrieve a value and add some value to it reverse engineering, problema con le relazioni di default 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 Setting Upload directory Share database connection Showing items that have a relation with an entity Shuffling Script Slot in Selection Field Solve "Generation Error" with Generate and Run option Standard confirm dialog replacement Statistics Component for WebRatio > 7.2.0 Status ProcessInstance and activityInstance in spanish Sybase JConnect 4 JAR replace Sync DataService Project with Mobile Project Table 'freeapp43.profesion' doesn't exist Tarea de servicio no me evalua el valor Trying to Synchronize Domain Model Unable to execute the script java.lang.NullPointerException Unknow property on Dynaclass after generation Unspecified BPM Engine Database Update fields based on selection of other fields Update mutiple records with the same value Updating attributes of an entity upload file html Uppercase User Login Timestamp Username come chiave Using own User and Group tables 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 Web ratio data model WebRatio - list results of joined tables Web Ratio Mobile and Foreign Key Web Ratio Mobile - Remote data mapping problem WebRation - Create Navigation diagram WebRatio no imports all attributes (fields) of a table What are the new features of WebRatio 6.1? Where is the ACME demo data stored?! which of these three models is closer to webratio/ifml way of creating web applications White report