Announcement

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

    getUploadedFileStream()

    I have a testcase in which the getUploadedFileStream() is not behaving as stated in the docs.

    EntryPoint:
    Code:
    public void onModuleLoad() {
    
    
    
    
    final VLayout vlayout = new VLayout(10);
    
    
    
    
    final DynamicForm editDokumenteForm = new DynamicForm();
    
    editDokumenteForm.setDataSource("testingDS");
    
    editDokumenteForm.setHeight("62%");
    
    editDokumenteForm.setWidth("100%");
    
    
    
    
    editDokumenteForm.setNumCols(2);
    
    editDokumenteForm.setColWidths("40%", "60%");
    
    editDokumenteForm.setPadding(5);
    
    
    
    
    FileItem fileItem = new FileItem("f_datei", "Datei");
    
    fileItem.setHeight(20);
    
    
    
    
    editDokumenteForm.setFields(fileItem);
    
    
    
    
    vlayout.addMember(editDokumenteForm);
    
    
    
    
    IButton saveButton = new IButton("Save");
    
    vlayout.addMember(saveButton);
    
    
    
    
    saveButton.addClickHandler(new ClickHandler() {
    
    
    
    
    @Override
    
    public void onClick(ClickEvent event) {
    
    editDokumenteForm.saveData(new DSCallback() {
    
    
    
    
    @Override
    
    public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
    
    SC.say("Saved");
    
    }
    
    
    
    
    });
    
    }
    
    });
    
    
    
    
    Criteria c = new Criteria();
    
    c.addCriteria("f_id", 85);
    
    editDokumenteForm.fetchData(c);
    
    
    
    
    vlayout.draw();
    
    }
    It just selects a document with f_id=85. You have to have a table with this id and with f_datei as binary.

    testingDS.ds.xml:
    Code:
    <DataSource ID="testingDS" serverType="sql" tableName="t_dokumente">
    
    
    
    
    <fields>
    
    <field name="f_id" type="sequence" primaryKey="true" />
    
    <field name="f_datei" type="binary" maxFileSize="10485760" />
    
    <field name="f_datei_filename" type="text" />
    
    <field name="f_datei_date_created" type="date" />
    
    <field name="f_datei_filesize" type="integer" />
    
    </fields>
    
    
    
    
    <operationBindings>
    
    <operationBinding operationType="update">
    
    <serverObject className="de.mks_infofabrik.kids.server.test.TestingDMI"
    
    methodName="testMethod" />
    
    </operationBinding>
    
    </operationBindings>
    
    
    
    
    </DataSource>
    TestingDMI:

    Code:
    public class TestingDMI {
    
    
    
    
    private static final Logger LOG = Utils.getLogger(TestingDMI.class);
    
    
    
    
    public DSResponse testMethod(DSRequest dsRequest) throws Exception {
    
    
    
    
    LOG.info("TestingDMI: ExecuteMethod()");
    
    
    
    
    Map<String, Object> values = dsRequest.getValues();
    
    LOG.info("values.get(\"f_datei\") " + values.get("f_datei"));
    
    
    
    
    LOG.info("Uploaded stream: " + dsRequest.getUploadedFileStream("f_datei"));
    
    
    
    
    return new DSResponse();
    
    }
    
    }
    If you open the application and don't upload any file, so just press the button "save", you will get this output:

    Code:
    === 2017-11-29 13:54:47,203 [ec-6] INFO  TestingDMI - TestingDMI: ExecuteMethod()
    === 2017-11-29 13:54:47,204 [ec-6] INFO  TestingDMI - values.get("f_datei") null
    === 2017-11-29 13:54:47,204 [ec-6] INFO  TestingDMI - Uploaded stream: java.io.ByteArrayInputStream@7053707

    According to the docs: https://www.smartclient.com/smartgwt...a.lang.String-
    "InputStream representing uploaded file for specified field, or null if no file was uploaded for the specified field."

    So the uploaded stream should be null.
    Please check this. I was relying in this and my client has lost a lot of data because of this behavior.

    Using 6.1-p20171105 power

    #2
    Hi Isomorphic,

    are you able to reproduce this issue ?

    Comment


      #3
      This is queued to be looked at. A couple of quick points:

      1. it's possible that this is caused by using a newer or older version of commons-fileupload, or by some layer you've placed in front of the SmartGWT server code that is modifying the request in some way before we receive it

      2. a workaround is to try reading the stream to check whether it's empty, and this would be a valuable protection against accidental upload of zero-length files, corrupt files or other sources of user error that could destroy data

      Comment


        #4
        1. No, I am using the commons-fileupload imported by isomorphic maven dependency: its version is 1.3.3. And I am not using any other layer in front.
        2. Yes, this would be a workaround. But I would prefer this to be fixed. The check would work as a protection, as you said, but at first place I need the null value as stated by the javadocs.

        Thanks

        Comment


          #5
          Hi Isomorphic,

          any information about this ? Have you been able to reproduce the issue?
          Last edited by edulid; 18 Dec 2017, 07:12.

          Comment


            #6
            Hi Isomorpic,

            any update on this issue?

            Comment


              #7
              Apologies for the delay. This is fixed and is available for downloads in latest nightly build.

              Comment

              Working...
              X