uploading file to the server

I’m sorry to post once again, but I am having problems.

When I post from an HTML form, all works fine. But when I post from Servoy, I get a successful upload message. However, the file is not there.

Thanks,
Rachel

var chosenFile = plugins.file.showFileOpenDialog(1);

//the global “gUserFileSeparator” holds either "" for PC or “/” for Mac OS X
var os = application.getOSName();

if(os.indexOf(‘Mac’,1) != -1) {
userFileSeparator = ‘/’;
} else {
userFileSeparator = ‘\’;
}

//set the variable “fName” to the entire path of the document
var filePath = chosenFile.getPath();
var fileName = chosenFile.getName();

plugins.dialogs.showInfoDialog( filePath, fileName, ‘Ok’);

var data = application.readFile(chosenFile);

var localFile = plugins.file.getFileSize(filePath);

if (localFile) {
//Set status area to give some feedback to the user
application.setStatusText(‘Uploading…’);
application.updateUI();

//HTTP post execution
var poster = plugins.http.getPoster(‘http://www.brucel.com/upload.php’);
var didAddFile = poster.addFile(‘userfile’, fileName, filePath);
var httpCode = poster.doPost(); //(httpCode 200 is ok)

if ( httpCode == ‘200’ ) {
plugins.dialogs.showInfoDialog( ‘Web Upload’, ‘Upload successful.’, ‘Ok’);
} else {
plugins.dialogs.showErrorDialog( ‘Web Upload’, 'Upload Error: '+httpCode, ‘Doh!’);
}

//Reset the StatusBar
application.setStatusText(‘’);

} else {
plugins.dialogs.showErrorDialog( ‘Error!’, ‘The selected file doesn't exist.’, ‘OK!’);
}

I would like know how can I show an upload progression bar when uploading big files (10-100mb) using http (poster) plugin.

Thanks for you advise!

faheemhameed:
I would like know how can I show an upload progression bar when uploading big files (10-100mb) using http (poster) plugin.

Use an animated gif:

http://www.servoymagazine.com/home/2006/06/tip_showing_sta.html

The animated image does not really show the animation if the long running script is in progress. If I add application.sleep(1000) in the middle of the method, the animation shows just for that one second. Then it just shows the image without the animation.

How it works in your case?

I am showing the animated image in the it2be splash dialog.

It is possible to open the splash in a new Thread? How can I do it? Will it solve the issue?

I know when a long running method is running and I click another button to initiate another method, the later method runs on a separate Thread. But How can I start a new Thread from within a method? (without clicking any other button to initiate it)

Thanks!

Unfortunately, splash or not, you can’t…

Are you saying that this tip is really not worth it for showing animated progress for long running methods?

http://www.servoymagazine.com/home/2006 … g_sta.html

Will the spinner in your dialog plugin show some kind of animated progress well?

Do you do that within a separate Thread?

Thanks!

I have a file stream plugin I’ve been working on that currently does the opposite. It takes in a path on the server, path on the client, and bufferAmt. So it coppies a file from the server, down to the client. A few modifications and it could be workinng to go the opposite way.

Can I give a try at your plugin? Thanks!

This is the current plugin that coppies from the server to the client. I have some commenting and example code still to do. The use is like this..

String from, String to, int bufferSize

where “from” is the server path, “to” is the client path, and I recommend 1024 as the bufferSize

I have a few issues sometimes putting it on the app server…I get a message about port 1099 being in use…but let me know if it works for you.

ddc_filestream.jar (10.9 KB)

Are you saying that this tip is really not worth it for showing animated progress for long running methods?

http://www.servoymagazine.com/home/2006 … g_sta.html

Will the spinner in your dialog plugin show some kind of animated progress well?

Do you do that within a separate Thread?

That tip is certainly worth something as long as what you are doing is not giving too much workload (see my comment also). The same issue arises with the dialog plugin/progress method. I won’t go into detail to why but it is, unfortunately, not possible to do this is a seperate thread :(

Hi Marcel,

Thanks for your explanation. It is unfortunate that we can’t get it to work as required. I would definitely looking for something which can show a progress bar during download and upload process.

Hi Scott,

I am trying to use your plugin now:

Can you give me some example code?

where “from” is the server path, “to” is the client path, and I recommend 1024 as the bufferSize

What is server path (is it an httpPath?) and client path (c:/temp/temp.gif?)

Thanks!

It is unfortunate that we can’t get it to work as required. I would definitely looking for something which can show a progress bar during download and upload process.

The way to achieve that is by using my DataStream Plugin.

The precise reason for introducing such a plugin was to provide progress feedback for the transfer of resources up and down the wire.

Importantly, you can determine whether the transfer runs on the same thread as your Servoy method (unwise !) or on another separate thread dedicated to the stream read/write activity.

You can get all the details here:
http://www.cybersack.com/

Can you give me some example code?

I posted some sample code with the updated plugin. I posted a forum topic at http://forum.servoy.com/viewtopic.php?t=6760 that also has some addition examples that I just added.

What is server path (is it an httpPath?) and client path (c:/temp/temp.gif?)

The paths are just standard File paths, like you would use with the File plugin. So, the local file path on the App server, and the local file path on the client machine.

Thanks Scott!

I will try it out.

This is the solution for your problem. New FTP plugin “mpFTP”.

Please check
http://forum.servoy.com/viewtopic.php?t=6985