Ask and answer questions about WebRatio, WebML and BPMN

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.

asked 22 Sep '11, 10:52

Juanmos's gravatar image

Juanmos
0111
accept rate: 0%


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 ( http://wiki.webratio.com/index.php/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.

link

answered 29 Sep '11, 08:53

michelafrigerio's gravatar image

michelafrigerio
29514
accept rate: 63%

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. http://wiki.webratio.com/index.php/How_to_deal_with_BLOBs.

link

answered 12 Oct '11, 03:25

LorenzoDV's gravatar image

LorenzoDV
1754
accept rate: 66%

edited 13 Dec '11, 04:49

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.

link

answered 23 Sep '11, 05:44

michelafrigerio's gravatar image

michelafrigerio
29514
accept rate: 63%

Thanks for the response.

But i forgot to explain that I`m not uploading it to a database, i want to upload the file to an specific folder with and specific name.

thanks

(28 Sep '11, 10:09) Juanmos
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×2
×1

Asked: 22 Sep '11, 10:52

Seen: 306 times

Last updated: 13 Dec '11, 04:49

©2001-2011 Web Models s.r.l. All rights reserved