uploading files in web client

Hi

We are currently re factoring our solution to allow users to use the web client, this is our first experience of web client coding so im a little lost as to the differences in what we can and cant use.

Currently we have a module which allows users to upload images, which are then renamed and stored on disk on the server.

I need to achieve the same thing in web client.

What is the best way to do the following

  1. Selecting a file
  2. Grabbing the name of said file
  3. Uploading said file to a path on the server
  4. Then renaming said file.

Thanks

bump

the only thing you can do is first let the users upload the files by calling the plugins.file.showFileOpenDialog() (you have to specify the call back function)

Then when the users have selected 1 or more file to upload, those are being uploaded and when that is done your callback function will be called with a JSFile array of the uploaded files
For that you can ask the name/bytes/contenttype and store them on the server or db.
If the user can specify a directory on the server, you could first ask for that dir, then remember that and then call showFileOpenDialog()

Thanks for this

What is the correct syntax to extract the file details from the file array ie name etc?

see JSFile api for that.

Hi

Im having difficulty getting this straight.

So the user has uploaded a file and I have the JSFile Array returned to my callback function.

Is that file now physically present on the server or in memory?
And if in memory
Am I correct in thinking that I now need to write that file to the server using plugins.file.writeFile ?

Also where do the files get uploaded to? The default upload directory ?

they are in memory or cached onto a tmp dir if they are bigger then a certain size.
You then should write the files to disk on the server by using writeFile (or stream)

They are not uploaded to a default upload dir, only a tmp dir could be used.

to use writeFile() you have to do something like:

var myuploadedfile = callbackarray[0];
var serverfile = plugins.file.createFile("path/on/server");
plugins.file.writeFile(serverfile,myuploadedfile.getBytes());

Thats nailed it Thanks

Dear Johan and Zuke,

I am trying with that code but no file is written into the Server

function onUpload(event) {
plugins.file.showFileOpenDialog(1, null, false, null, uploadCallBack, ‘Select your Resume file’ );
}

/**

  • @param {Array} files
  • @private
  • @properties={typeid:24,uuid:“D175AC4F-C72F-43E9-9390-7AE46E28B347”}
    */
    function uploadCallBack(files) {
    var myuploadedfile = files[0];
    var serverfile = plugins.file.createFile(“/” + “myfile.pdf”);
    plugins.file.writeFile(serverfile,myuploadedfile.getBytes());
    }

is uploadcallback called?
also what file are you creating there? Do you have write access to plain root ?? (/name.pdf)

Thank you Johan!

It was a problem with permisions. I tried with a diferent path and worked fine.

Thank you

I am trying same code and while it uploads the file I get a warning:

plugins.file.writeFile(serverfile,myuploadedfile.getBytes()); // The method getBytes() is undefined for object myuploadedfile

What is wrong?

This seems to fix it:

var myuploadedfile = files[0].getBytes()
var serverfile = plugins.file.createFile("d:/myfile.png")	
plugins.file.writeFile(serverfile,myuploadedfile)