Announcement

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

    Can't get FileUpload to work

    Hi,

    I am trying to implement a file upload facility inside my application. I am currently using v11.0p_2016-04-12/EVAL Deployment (my company is currently trying to buy a production license...).

    I have put a DynamicForm containing a FileItem inside a MenuButton as an embeddedComponent:

    Code:
        var uform = isc.DynamicForm.create({
          autoDraw : false,
          ID : "uploadForm",
          dataSource : "uploads",
          fields : [
              {
                name : "attachment",
                type : "binary",
                showTitle : false
              },
              {
                title : "Invia",
                type : "button",
                startRow : false,
                click : function() {
                  this.form.saveData(function(res, data, req) {
                    if (res.status >= 0) {
                      nebulaerp.util.addAttachments(tb, data.attachments, form,
                          parentBO);
                    }
                  });
                }
              } ]
        });
        var items = attachments.map(function(el) {
          return {
            title : el.description,
            icon : "[SKIN]/../actions/download.png",       
            click : function() {
              util.performAction("DocDownload", form, {
                key : el.code
              }, nebulaerp.util.openFile);
            }
          }
        });
        uform.dataSource.addProperties({
          transformRequest : function(req) {
            req.data.parentKey = form.getValue("key");
            req.data.parentBO = parentBO;
          }
        });
        uform.editNewRecord({
          code : "1"
        });
        items.splice(0, 0, {
          embeddedComponent : uform,
          embeddedComponentFields : [ "title", "key" ],
          icon : "[SKIN]/../actions/upload.png",
          showRollOver: false
        });
        var menu = isc.Menu.create({
          autoDraw : false,
          data : items
        });
        var attmenu = isc.MenuButton
            .create({
              ID : form.ID + "_att",
              autoDraw : false,
              title : "<img src='"
                  + menu
                      .getImgURL(attachments.length > 0 ? "[SKIN]/../actions/download.png"
                          : "[SKIN]/../actions/download_Disabled.png")
                  + "'></img>Allegati",
              menu : menu
            });
    The datasource definition is very simple:

    <DataSource ID="uploads" serverConstructor="it.interprise.core.isc.UploadDataSource">
    <fields>
    <field name="code" primaryKey="true" type="text" hidden="true" />
    <field name="parentKey" type="text" hidden="true" />
    <field name="description" type="text" />
    <field name="attachment" type="binary" />
    </fields>
    </DataSource>

    When I click on the button I get this server side stack trace:

    Request start
    POOLER: conn taken total: 2 avail: 1 busy: 1
    byKey: [S0018AMM] UTENTI WHERE LOGIN = ?
    byKey: [S0018, 0] VALUTE WHERE CODICE_PART = ? AND ID_VALUTA = ?
    === 2016-07-04 16:31:24,402 [ec-2] INFO RequestContext - URL: '/entrasp/isomorphic/IDACall', User-Agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36': Safari with Accept-Encoding header
    === 2016-07-04 16:31:24,473 [ec-2] DEBUG XML - Parsed XML from (in memory stream): 7ms
    === 2016-07-04 16:31:24,475 [ec-2] DEBUG RPCManager - Processing 1 requests.
    === 2016-07-04 16:31:24,476 [ec-2] DEBUG XML - Parsed XML from /home/luca/kepler-ws/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/shared/ds/uploads.ds.xml: 1ms
    === 2016-07-04 16:31:27,855 [ec-2] ERROR IDACall - com.isomorphic.servlet.IDACall top-level exception
    java.lang.NullPointerException
    at com.isomorphic.datasource.DSRequest.parseUploadedFiles(DSRequest.java:701)
    at com.isomorphic.datasource.DSRequest.<init>(DSRequest.java:674)
    at com.isomorphic.rpc.RPCManager.parseRequest(RPCManager.java:2309)
    at com.isomorphic.rpc.RPCManager.<init>(RPCManager.java:369)
    at com.isomorphic.rpc.RPCManager.<init>(RPCManager.java:349)
    at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:147)
    at com.isomorphic.servlet.IDACall._processRequest(IDACall.java:119)
    at com.isomorphic.servlet.IDACall.doPost(IDACall.java:79)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:162)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at com.isomorphic.servlet.CompressionFilter._doFilter(CompressionFilter.java:260)
    at com.isomorphic.servlet.BaseFilter.doFilter(BaseFilter.java:88)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at it.interprise.core.SessionFilter.doFilter(SessionFilter.java:35)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
    === 2016-07-04 16:31:27,858 [ec-2] DEBUG ConfigParser - Matched var name: debug
    === 2016-07-04 16:31:27,858 [ec-2] DEBUG ConfigParser - value after substitution: true
    === 2016-07-04 16:31:27,861 [ec-2] INFO Compression - /entrasp/isomorphic/IDACall: 4234 -> 796 bytes
    POOLER: conn released total: 2 avail: 2 busy: 0
    Request end

    I see that the DataSource is correctly instantiated but uploadedFiles is null. It seems to me also that the request is not sending the file since there is no apparent delay between pressing the button and getting the exception from the server side code. Another thing that happens is that the client hangs waiting until a timeout happens.

    Maybe I've made something stupid.
    If someone can help me I'll be grateful.
    Last edited by lveronese; 4 Jul 2016, 06:34.

    #2
    Hello, please format the code with the [CODE] tags, otherwise it's very hard to read it. Also, post the server logs.

    Comment


      #3
      I did as requested, thank you.

      Comment


        #4
        First things to check:
        1. Use the built-in browser tools (usually just press f12 to open these) to see if there is a file being sent to the server or not. Commonly, this kind of problem happens because server-side libraries are intercepting the request before SmartClient gets it, and dropping the file

        2. Turn on the "redraws" log to see if your form is being redrawn sometime in the save process. If so, this would drop the file that has been selected by the user. This is tricky to avoid since the grid needs to redraw the body area and embedded components in many circumstances; the most reliable approach for a file upload that must be triggered from a grid is to pop open a modal dialog that contains your upload form, a complete the save there

        Comment


          #5
          Probably the problem is the second one.
          I get this request sent:

          Code:
          ------WebKitFormBoundaryNmWXez0WJBTDZKog
          Content-Disposition: form-data; name="attachment"; filename="image001.jpg"
          Content-Type: image/jpeg
          
          
          ------WebKitFormBoundaryNmWXez0WJBTDZKog
          Content-Disposition: form-data; name="_transaction"
          
          <transaction xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:type="xsd:Object"><transactionNum xsi:type="xsd:long">7</transactionNum><operations xsi:type="xsd:List"><elem xsi:type="xsd:Object"><values xsi:nil="true"/><operationConfig xsi:type="xsd:Object"><dataSource>uploads</dataSource><repo xsi:nil="true"/><operationType>add</operationType><textMatchStyle>exact</textMatchStyle></operationConfig><componentId>isc_DynamicForm_2</componentId><appID>builtinApplication</appID><operation>uploads_add</operation><oldValues xsi:type="xsd:Object"></oldValues></elem></operations><jscallback>iframe</jscallback></transaction>
          ------WebKitFormBoundaryNmWXez0WJBTDZKog--

          Comment

          Working...
          X