Announcement

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

    getFileURL and Img.src

    Dear Support,

    as suggested in DataSource.getFileURL() we are using this method to get an url to an image stored in the DB that we can then pass to an Img widget.

    Here is the (simple test case) data source:
    Code:
    <DataSource
        ID="test"
           serverType="sql"
           tableName="SYS_ATTACHMENT"
    >
        <fields>
            <field name="ID" type="sequence" sequenceName="SQ_SYS_ATTACHMENT" hidden="true" primaryKey="true" />
                 <field name="ATTACHMENT" type="image" title="$attachment"/>
        </fields>
        
    </DataSource>
    We call the service, which returns a rather long URL:
    Code:
    Record r = new Record();
    r.setAttribute(DSImageAttachment.ID, pictureId);
    String url = DataSource.get("test").getFileURL(r, "ATTACHMENT");
    The URL:

    Code:
    http://127.0.0.1:8888/application/sc/IDACall/undefined?isc_rpc=1&isc_v=v9.0p_2013-10-01&isc_tnum=13&_transaction=%3Ctransaction%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2F10%2FXMLSchema-instance%22%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CtransactionNum%20xsi%3Atype%3D%22xsd%3Along%22%3E13%3C%2FtransactionNum%3E%3Coperations%20xsi%3Atype%3D%22xsd%3AList%22%3E%3Celem%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3Ccriteria%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3Cdownload_fieldname%3EATTACHMENT%3C%2Fdownload_fieldname%3E%3C%2Fcriteria%3E%3CoperationConfig%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CdataSource%3Etest%3C%2FdataSource%3E%3CoperationType%3EviewFile%3C%2FoperationType%3E%3C%2FoperationConfig%3E%3CuseStrictJSON%20xsi%3Atype%3D%22xsd%3Aboolean%22%3Etrue%3C%2FuseStrictJSON%3E%3CappID%3EbuiltinApplication%3C%2FappID%3E%3Coperation%3Etest_viewFile%3C%2Foperation%3E%3ColdValues%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3Cdownload_fieldname%3EATTACHMENT%3C%2Fdownload_fieldname%3E%3C%2FoldValues%3E%3C%2Felem%3E%3C%2Foperations%3E%3C%2Ftransaction%3E
    But the data never comes up to the client... we can see a DSRequest issued in the RPC tab, but it stays as "Transaction in Progress", no specific error in the output...
    If we copy/paste the URL in the address bar of a browser, we receive a 200 of type html/text.

    Can you please help us?
    Many thanks (and happy new year to all the team!),

    Regards,
    Thomas

    #2
    We need the server log for the request, and you should look at what Firebug reports as the response when you try the URL in your actual application (not standalone).

    We also need to know the values for all the metadata fields (see Binary Fields overview) stored along with this record.

    Comment


      #3
      Sure,

      Here are our latests modifications/observations:

      Updated DS sample with the metadata fields:

      Code:
      <DataSource
          ID="test"
             serverType="sql"
             tableName="SYS_ATTACHMENT"
      >
          <fields>
              <field name="ID" type="sequence" sequenceName="SQ_SYS_ATTACHMENT" hidden="true" primaryKey="true" />
                    <field name="ATTACHMENT" type="imageFile" title="$attachment"/>
                   <field name="ATTACHMENT_DATE_CREATED" type="datetime" hidden="true"/>
              <field name="ATTACHMENT_FILENAME" type="text" title="$fileName"/>
              <field name="ATTACHMENT_FILESIZE" type="integer" title="$fileSize"/>
              <field name="ATTACHMENT_MIME_TYPE" type="text" title="$mimeType"/>
          </fields>
          
      </DataSource>
      Our latest generated URL:
      Code:
      http://127.0.0.1:8888/application/sc/IDACall/undefined?isc_rpc=1&isc_v=v9.0p_2013-10-01&isc_tnum=5&_transaction=%3Ctransaction%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2F10%2FXMLSchema-instance%22%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CtransactionNum%20xsi%3Atype%3D%22xsd%3Along%22%3E5%3C%2FtransactionNum%3E%3Coperations%20xsi%3Atype%3D%22xsd%3AList%22%3E%3Celem%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3Ccriteria%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CID%3E38%3C%2FID%3E%3C%2Fcriteria%3E%3CoperationConfig%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CdataSource%3Etest%3C%2FdataSource%3E%3CoperationType%3EviewFile%3C%2FoperationType%3E%3C%2FoperationConfig%3E%3CuseStrictJSON%20xsi%3Atype%3D%22xsd%3Aboolean%22%3Etrue%3C%2FuseStrictJSON%3E%3CappID%3EbuiltinApplication%3C%2FappID%3E%3Coperation%3Etest_viewFile%3C%2Foperation%3E%3ColdValues%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CID%3E38%3C%2FID%3E%3C%2FoldValues%3E%3C%2Felem%3E%3C%2Foperations%3E%3C%2Ftransaction%3E
      The HTML returned by the server when putting the URL directly in the address bar:

      Code:
      <HTML>
      <BODY ONLOAD='var results = document.formResults.results.value;null'><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><FORM name='formResults'><TEXTAREA readonly name='results'>
      //isc_RPCResponseStart-->[{data:{ATTACHMENT_MIME_TYPE:"image/png",ATTACHMENT_DATE_CREATED:new Date(1389019456000),ATTACHMENT_FILENAME:"functions.png",ID:38,ATTACHMENT_FILESIZE:4822},endRow:1,invalidateCache:false,isDSResponse:true,operationType:"viewFile",queueStatus:0,startRow:0,status:0,totalRows:1}]//isc_RPCResponseEnd</TEXTAREA></FORM>
      </BODY></HTML>
      When we are setting Img.src with the URL, we see the DSRequest issued by the client, but no response... Here is the server logs (Still "Transaction In Progress" in the console)

      Code:
      === 2014-01-07 14:05:30,385 [l0-4] INFO  RequestContext - URL: '/application/sc/IDACall/undefined', User-Agent: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)': MSIE with Accept-Encoding header, ready for compressed JS
      === 2014-01-07 14:05:30,397 [l0-4] DEBUG XML - Parsed XML from (in memory stream): 11ms
      === 2014-01-07 14:05:30,399 [l0-4] DEBUG RPCManager - Processing 1 requests.
      === 2014-01-07 14:05:30,399 [l0-4] DEBUG DSRequest - Caching instance 61 of DS test from DSRequest.getDataSource()
      === 2014-01-07 14:05:30,399 [l0-4] DEBUG RPCManager - Request #1 (DSRequest) payload: {
          criteria:{
              ID:"38"
          },
          operationConfig:{
              dataSource:"test",
              operationType:"viewFile"
          },
          useStrictJSON:true,
          appID:"builtinApplication",
          operation:"test_viewFile",
          oldValues:{
              ID:"38"
          }
      }
      === 2014-01-07 14:05:30,399 [l0-4] INFO  IDACall - Performing 1 operation(s)
      === 2014-01-07 14:05:30,399 [l0-4] DEBUG DeclarativeSecurity - Processing security checks for DataSource null, field null
      === 2014-01-07 14:05:30,399 [l0-4] DEBUG DeclarativeSecurity - DataSource test is not in the pre-checked list, processing...
      === 2014-01-07 14:05:30,400 [l0-4] DEBUG AppBase - [builtinApplication.test_viewFile] No userTypes defined, allowing anyone access to all operations for this application
      === 2014-01-07 14:05:30,400 [l0-4] DEBUG AppBase - [builtinApplication.test_viewFile] No public zero-argument method named '_test_viewFile' found, performing generic datasource operation
      === 2014-01-07 14:05:30,400 [l0-4] DEBUG DeclarativeSecurity - [builtinApplication.test_viewFile] Processing security checks for DataSource null, field null
      === 2014-01-07 14:05:30,400 [l0-4] DEBUG AppBase - [builtinApplication.test_viewFile, builtinApplication.null] No userTypes defined, allowing anyone access to all operations for this application
      === 2014-01-07 14:05:30,400 [l0-4] DEBUG AppBase - [builtinApplication.test_viewFile, builtinApplication.null] No public zero-argument method named '_null' found, performing generic datasource operation
      === 2014-01-07 14:05:30,400 [l0-4] INFO  SQLDataSource - [builtinApplication.test_viewFile, builtinApplication.null] Performing fetch operation with
             criteria: {ID:"38"} values: {ID:"38"}
      === 2014-01-07 14:05:30,401 [l0-4] INFO  SQLDataSource - [builtinApplication.test_viewFile, builtinApplication.null] derived query: SELECT $defaultSelectClause FROM $defaultTableClause WHERE $defaultWhereClause
      === 2014-01-07 14:05:30,401 [l0-4] INFO  SQLDataSource - [builtinApplication.test_viewFile, builtinApplication.null] 61: Executing SQL query on 'FIRCO': SELECT SYS_ATTACHMENT.ATTACHMENT, SYS_ATTACHMENT.ATTACHMENT_DATE_CREATED, SYS_ATTACHMENT.ATTACHMENT_FILENAME, SYS_ATTACHMENT.ATTACHMENT_FILESIZE, SYS_ATTACHMENT.ATTACHMENT_MIME_TYPE, SYS_ATTACHMENT.ID FROM SYS_ATTACHMENT WHERE (SYS_ATTACHMENT.ID=38)
      === 2014-01-07 14:05:30,401 [l0-4] DEBUG PoolableSQLConnectionFactory - [builtinApplication.test_viewFile, builtinApplication.null] makeObject() created an unpooled Connection '1595476180'
      === 2014-01-07 14:05:30,402 [l0-4] DEBUG SQLConnectionManager - [builtinApplication.test_viewFile, builtinApplication.null] Borrowed connection '1595476180'
      === 2014-01-07 14:05:30,402 [l0-4] DEBUG SQLDriver - [builtinApplication.test_viewFile, builtinApplication.null] About to execute SQL query in 'FIRCO' using connection '1595476180'
      === 2014-01-07 14:05:30,402 [l0-4] INFO  SQLDriver - [builtinApplication.test_viewFile, builtinApplication.null] Executing SQL query on 'FIRCO': SELECT SYS_ATTACHMENT.ATTACHMENT, SYS_ATTACHMENT.ATTACHMENT_DATE_CREATED, SYS_ATTACHMENT.ATTACHMENT_FILENAME, SYS_ATTACHMENT.ATTACHMENT_FILESIZE, SYS_ATTACHMENT.ATTACHMENT_MIME_TYPE, SYS_ATTACHMENT.ID FROM SYS_ATTACHMENT WHERE (SYS_ATTACHMENT.ID=38)
      === 2014-01-07 14:05:30,403 [l0-4] INFO  DSResponse - [builtinApplication.test_viewFile, builtinApplication.null] DSResponse: List with 1 items
      === 2014-01-07 14:05:30,403 [l0-4] INFO  DSResponse - [builtinApplication.test_viewFile] DSResponse: Map with 6 keys
      === 2014-01-07 14:05:30,403 [l0-4] DEBUG RPCManager - Content type for RPC transaction: text/html; charset=UTF-8
      === 2014-01-07 14:05:30,403 [l0-4] DEBUG RPCManager - non-DMI response, dropExtraFields: false
      === 2014-01-07 14:05:30,405 [l0-4] DEBUG SQLTransaction - Returning transactional connection for FIRCO (connection is null)
      === 2014-01-07 14:05:30,405 [l0-4] DEBUG SQLDriver - Freeing SQLDriver dbConnection 1595476180
      === 2014-01-07 14:05:30,405 [l0-4] DEBUG SQLConnectionManager - About to close PoolGuardConnectionWrapper with hashcode "1595476180"
      === 2014-01-07 14:05:30,405 [l0-4] DEBUG SQLTransaction - Returning transactional connection for FIRCO (connection is null)
      200 - GET /application/sc/IDACall/undefined?isc_rpc=1&isc_v=v9.0p_2013-10-01&isc_tnum=5&_transaction=%3Ctransaction%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2F10%2FXMLSchema-instance%22%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CtransactionNum%20xsi%3Atype%3D%22xsd%3Along%22%3E5%3C%2FtransactionNum%3E%3Coperations%20xsi%3Atype%3D%22xsd%3AList%22%3E%3Celem%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3Ccriteria%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CID%3E38%3C%2FID%3E%3C%2Fcriteria%3E%3CoperationConfig%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CdataSource%3Etest%3C%2FdataSource%3E%3CoperationType%3EviewFile%3C%2FoperationType%3E%3C%2FoperationConfig%3E%3CuseStrictJSON%20xsi%3Atype%3D%22xsd%3Aboolean%22%3Etrue%3C%2FuseStrictJSON%3E%3CappID%3EbuiltinApplication%3C%2FappID%3E%3Coperation%3Etest_viewFile%3C%2Foperation%3E%3ColdValues%20xsi%3Atype%3D%22xsd%3AObject%22%3E%3CID%3E38%3C%2FID%3E%3C%2FoldValues%3E%3C%2Felem%3E%3C%2Foperations%3E%3C%2Ftransaction%3E (127.0.0.1) 564 bytes
      Thanks,
      Thomas

      Comment


        #4
        First problem is that you are faking the Record you are passing to getFileUrl - it lacks the filename and other attributes that this API needs. That's why the URL ends up with "undefined" as the filename, and this can cause the browser to interpret the result as the wrong type. You need to pass the complete Record as retrieved from the server to getFileURL().

        There could be further problems, but correct this first and retest.

        Comment


          #5
          Thank you very much for your help.

          Well, we added the full record as first parameter but it did not help... We also tried to add the full record in the last DSRequest parameter, no success...

          But... surprisingly if we revert back to a simple record with just the primary key but WITHOUT the second parameter, it's working perfectly. So either that second parameter was wrong (I don't see why in this test case) or there is a problem in the API in the way this second parameter is processed ?

          Anyway... as it's ok now you can close the case.

          Thanks again,
          Thomas

          Comment


            #6
            The fieldName parameter is optional per docs, and if an incorrect value is passed, it would indeed cause the API to fail, as expected.

            We see no apparent issue with use of the fieldName parameter, it works in our tests.

            While your call with the "simple" Record appears to work, it's incorrect usage, and could fail at any time. We recommend correcting this.

            Comment


              #7
              Thank you.

              So, if our datasource is the following, what should have we passed as second parameter ? We did pass "ATTACHMENT" and it did not work.

              Code:
              <DataSource
                  ID="test"
                     serverType="sql"
                     tableName="SYS_ATTACHMENT"
              >
                  <fields>
                      <field name="ID" type="sequence" sequenceName="SQ_SYS_ATTACHMENT" hidden="true" primaryKey="true" />
                            <field name="ATTACHMENT" type="imageFile" title="$attachment"/>
                           <field name="ATTACHMENT_DATE_CREATED" type="datetime" hidden="true"/>
                      <field name="ATTACHMENT_FILENAME" type="text" title="$fileName"/>
                      <field name="ATTACHMENT_FILESIZE" type="integer" title="$fileSize"/>
                      <field name="ATTACHMENT_MIME_TYPE" type="text" title="$mimeType"/>
                  </fields>
                  
              </DataSource>
              Eventually, for the first Record parameter, the javadoc says: "Record or value of primary key field for record containing the file to view". Maybe you should change this to underline that the full record should be passed ?

              Thanks,
              Thomas

              Comment


                #8
                Given what you've shared, "ATTACHMENT" is the right parameter. The problem is, if we pass the correct parameter in our tests, everything works as expected.

                Comment

                Working...
                X