0

i mode development in eclipse. the fileupload works just fine. but i will make directory to /var/wms/year/month/file.jpg on linux. this my source code from client: add component to form

fileUpload = new SingleUploader(FileInputType.LABEL);
    fileUpload.setFileInputPrefix("PJ");
    fileUpload.addOnFinishUploadHandler(onFinishUploaderHandler);
    layoutContainerItemRight.add(fileUpload, formData);

method is addOnFinishUploadHandler

private IUploader.OnFinishUploaderHandler onFinishUploaderHandler = new IUploader.OnFinishUploaderHandler() {
    public void onFinish(IUploader uploader) {
        if (uploader.getStatus() == gwtupload.client.IUploadStatus.Status.SUBMITING) {
            String month = VisionProperties.getBulan();
            String year = DateTimeFormat.getFormat( "d-M-yyyy" ).format( new Date() ).split( "-")[2];
            String strDirectoy = "/var/wms/" + year + "/" + month + "/";
            File file = new File(strDirectoy);
            if (!file.exists()) {
                file.mkdirs();
            }
        }

        if (uploader.getStatus() == gwtupload.client.IUploadStatus.Status.SUCCESS) {
        String msg  = uploader.getServerInfo().message;
        fileName    = msg.toString();
            if(selectWindow != 2){
                img.setUrl("servlet.gupld?show=&fieldname=" + fileName);
                itemPanel.render(img.getElement());
            }else{
                tb.setVisible(true);
                tb.setText("Download File "+uploader.getFileName());
            }
        }
    }
};

how to make directory file when upload file process?

Manolo Carrasco Moñino
  • 9,723
  • 1
  • 22
  • 27
mogi
  • 1
  • 3

2 Answers2

1

You are trying to use to use java.io.File in the client side which is not supported by the set of packages in the GWT jre emulation.

If you want to do this in client side you have to use the javascript File Api which is not supported by old browsers, and is not implemented in gwt-core. Using elemental you could use the Api only with Chrome, but I'm not positive. So it is better to wrap it via jsni, it is planned in gwtupload, but there is no a timeframe yet. Be aware that using js File Api, you dont have access to your real filesystem, but a virtual one inside your browser. To save created files in the local filesystem you have to download it using and iframe so as it asks the user where to save it.

Otherwise, If you wanted to do this work at server side, do it overriding the executeAction in your servlet if you are extending UploadAction.

Manolo Carrasco Moñino
  • 9,723
  • 1
  • 22
  • 27
  • i use executeAction create directory to server side. how to create directory folder before i'm upload file ? – mogi Apr 24 '13 at 10:07
  • You cannot create the folder before uploading. `UploadAction` recibes the file and saves it in a temporary folder, then calls `executeAction` and you can create dirs, copy the uploaded file to it, and remove the temporary one. – Manolo Carrasco Moñino Apr 24 '13 at 15:31
0

You cannot do this on client side. You can perform this on server side in the following ways

  1. before you upload the files to server by another rpc/http call.
  2. after you upload the files to server when the file upload servlet is being executed on the srever side.

HTML5 FILE API are restricted to readonly behavior in even modern browser.

Reference - 1. Basic File upload in GWT 2. How to retrieve file from GWT FileUpload component?

Community
  • 1
  • 1
appbootup
  • 9,537
  • 3
  • 33
  • 65
  • File api is RW, but in a restricted area of the browser (virtualized FS). – Manolo Carrasco Moñino Apr 24 '13 at 08:50
  • how to create directory folder before i'm upload file ? – mogi Apr 24 '13 at 10:06
  • Once you have client side part of the fileupload done i.e before submit you can fire an additional rpc call or http servlet call to get directory created. I would still prefer doing it in the second option in the file upload servlet. – appbootup Apr 24 '13 at 11:35