Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Problem with uploading the second file

    I am using SmartGWTPower 2.5, GWT 2.3, Firefox 10.0.2., Windows 7 (SmartClient Version: SC_SNAPSHOT-2011-08-02/PowerEdition Deployment (built 2011-08-02)). I have a form which contains 2 binary fields, only the first file has arrived successfully at the server side. Could you please help me solving the problem?

    server log: (normal mode):
    Code:
    INFO: ===  INFO 2012.03.01 11:04:24 (Logger.java:388) - URL: '/MyProject/myproject/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2': Moz (Gecko) with Accept-Encoding header
    
    INFO: === DEBUG 2012.03.01 11:04:24 (Logger.java:406) - Parsed XML from (in memory stream): 3ms
    
    INFO: === DEBUG 2012.03.01 11:04:24 (Logger.java:406) - Processing 1 requests.
    
    INFO: === DEBUG 2012.03.01 11:04:24 (Logger.java:406) - Request #1 (DSRequest) payload: {
        values:{
           fileFirst:"first.xml",
           fileSecond:"second.xml",
           _transaction:null,
           fileFirst_filename:"first.xml",
           fileFirst_filesize:7525,
           fileFirst_date_created:new Date(1330596264073)
        },
        operationConfig:{
           dataSource:"myMultiUpload",
           operationType:"add"
        },
        componentId:"isc_DynamicForm_2",
        appID:"builtinApplication",
        operation:"myMultiUpload_add",
        oldValues:{
        },
        criteria:{
        }
    }
    
    INFO: ===  INFO 2012.03.01 11:04:24 (Logger.java:388) - Performing 1 operation(s)
    
    INFO: === DEBUG 2012.03.01 11:04:24 (Logger.java:406) - [builtinApplication.myMultiUpload_add] No userTypes defined, allowing anyone access to all operations for this application
    
    INFO: === DEBUG 2012.03.01 11:04:24 (Logger.java:406) - [builtinApplication.myMultiUpload_add] No public zero-argument method named '_myMultiUpload_add' found, performing generic datasource operation
    
    INFO: ===  WARN 2012.03.01 11:04:24 (Logger.java:347) - [builtinApplication.myMultiUpload_add] No such type 'binary', not processing field value at /myMultiUpload/fileFirst
    
    INFO: ===  WARN 2012.03.01 11:04:24 (Logger.java:347) - [builtinApplication.myMultiUpload_add] No such type 'binary', not processing field value at /myMultiUpload/fileSecond
    
    
    INFO: fileDataFirst: [B@bd35a51 fileDataSecond: null
    INFO: fileFirst: java.io.ByteArrayInputStream@60ce81e7 fileSecond: second.xml
    INFO: ===  INFO 2012.03.01 11:04:27 (Logger.java:388) - [builtinApplication.myMultiUpload_add] DSResponse: Map with 2 keys
    
    INFO: === DEBUG 2012.03.01 11:04:27 (Logger.java:406) - Content type for RPC transaction: text/html; charset=UTF-8
    
    INFO: === DEBUG 2012.03.01 11:04:27 (Logger.java:406) - non-DMI response, dropExtraFields: true
    
    INFO: ===  INFO 2012.03.01 11:04:27 (Logger.java:388) - /UIKeretLearningProject/uikeretlearningproject/sc/IDACall: 453 -> 285 bytes
    DSRequest (Developer Console):
    Code:
    {
        "dataSource":"myMultiUpload",
        "operationType":"add",
        "componentId":"isc_DynamicForm_2",
        "data":{
           "fileFirst":"first.xml",
           "fileSecond":"second.xml"
        },
        "callback":{
           "target":[DynamicForm ID:isc_DynamicForm_2],
           "methodName":"saveEditorReply"
        },
        "showPrompt":true,
        "prompt":"Űrlap mentése...",
        "oldValues":{
        },
        "clientContext":{
        },
        "requestId":"myMultiUpload$6271"
    }
    ds.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <DataSource ID="myMultiUpload" serverConstructor="my.app.server.ds.MyMultiUploadFormDataSource">
     <fields>
       <field name="id" primaryKey="true" type="sequence" hidden="true" />
       <field name="fileFirst" title="Choose the FIRST file" type="binary" required="true" />
       <field name="fileFirst_date_created" title="" type="date" hidden="true" />
       <field name="fileFirst_filename" title="" type="text" hidden="true" />
       <field name="fileFirst_filesize" title="" type="number" hidden="true" />
       <field name="fileSecond" title="Choose the SECOND file" type="binary" required="true" />
       <field name="fileSecond_date_created" title="" type="date" hidden="true" />
       <field name="fileSecond_filename" title="" type="text" hidden="true" />
       <field name="fileSecond_filesize" title="" type="number" hidden="true" />
     </fields>
    </DataSource>
    client:
    Code:
    public class MyMultiUploadFormWidget extends VLayout {
       public MyMultiUploadFormWidget() {
           super(15);
           final DynamicForm frmUpload = new DynamicForm();
           frmUpload.setDataSource(DataSource.get("myMultiUpload"));
           frmUpload.setEncoding(Encoding.MULTIPART);
           addMember(frmUpload);
           IButton btnSave = new IButton("Save");
           btnSave.addClickHandler(new ClickHandler() {
               @Override
               public void onClick(ClickEvent event) {
                   frmUpload.saveData();
               }
           });
           addMember(btnSave);
       }
    }
    server:
    Code:
    public class MyMultiUploadFormDataSource extends BasicDataSource {
    ...
       public DSResponse executeAdd(DSRequest req) throws Exception {
           ISCFileItem iscFileItemFirst = req.getUploadedFile("fileFirst");
           ISCFileItem iscFileItemSecond = req.getUploadedFile("fileSecond");
           byte[] fileDataFirst = null;
           if (iscFileItemFirst != null) {
               fileDataFirst = iscFileItemFirst.get();
           }
           byte[] fileDataSecond = null;
           if (iscFileItemSecond != null) {
               fileDataSecond = iscFileItemSecond.get();
           }
           System.out.println("fileDataFirst: " + fileDataFirst + " fileDataSecond: " + fileDataSecond);
           ByteArrayInputStream fileFirst = (ByteArrayInputStream) req.getValues().get("fileFirst");
           String fileSecond = (String) req.getValues().get("fileSecond");
           System.out.println("fileFirst: " + fileFirst + " fileSecond: " + fileSecond);
           DSResponse resp = new DSResponse();
           @SuppressWarnings("rawtypes")
           Map data = new LinkedHashMap();
           data.put("fileFirst_filename", iscFileItemFirst.getFileName());
           data.put("fileFirst_filesize", fileDataFirst.length);
           resp.setData(data);
           resp.setSuccess();
           return resp;
       }
    }

    #2
    See docs for FileItem - it provides upload capability that works exactly like any other field (can have validation errors, etc) but with the limitation that you can only have one per form. So you will need a second form, which you can make look like it's all one form by just putting both forms into a VLayout.

    Comment


      #3
      Thank you for the fast reply.

      Comment

      Working...
      X