Menu

filename / blobs

Help
MisterT
2005-02-14
2013-06-03
  • MisterT

    MisterT - 2005-02-14

    Hi!
    Is it possible to store the filename only in the interceptor field instead of store the full path of the file?
    Thanks in advance

    regards theo

     
    • Henner Kollmann

      Henner Kollmann - 2005-02-15

      Which version do you use? How is your field defined?

      I think that the current version of dbforms stores only the filename without the path in the database!

      Cheers,
      Henner

       
      • MisterT

        MisterT - 2005-02-16

        I'm using version 2.4 on a MySQL 4.0.21 db.
        The interceptor field is a varchar(255) field.

        The definition in the dbforms-config.xml:

            <table name="cto_docs"
                        defaultVisibleFields="id" >
                <field name="id" fieldType="int" size="11" isKey="true" autoInc="true"/>
                <field name="name" fieldType="varchar" size="50"/>
                <field name="is_locked" fieldType="int" size="11"/>
                <field name="current_step_id" fieldType="int" size="11"/>
                <field name="xdt_file" fieldType="blob" size="16277215"/>
                <field name="xdt_file_name" fieldType="varchar" size="255"/>
                <field name="tsl_file" fieldType="blob" size="16277215"/>
                <field name="tsl_file_name" fieldType="varchar" size="255"/>
                <field name="pf_file" fieldType="blob" size="16277215"/>
                <field name="pf_file_name" fieldType="varchar" size="255"/>
                <field name="pdf_file" fieldType="blob" size="16277215"/>
                <field name="pdf_file_name" fieldType="varchar" size="255"/>
                <field name="pdf_lock" fieldType="int" size="11"/>

                <interceptor className="org.dbforms.event.BlobInterceptor">
                  <param name="blob-column1" value="xdt_file"/>
                  <param name="name-column1" value="xdt_file_name"/>
                  <param name="blob-column2" value="tsl_file"/>
                  <param name="name-column2" value="tsl_file_name"/>           
                  <param name="blob-column3" value="pf_file"/>
                  <param name="name-column3" value="pf_file_name"/>           
                  <param name="blob-column4" value="pdf_file"/>
                  <param name="name-column4" value="pdf_file_name"/>           
                </interceptor>

                <!-- add "granted-privileges" element for security constraints -->

            </table>

        Regards Theo

         
        • Henner Kollmann

          Henner Kollmann - 2005-02-16

          Could you try the current developers build? I rework the blob stuff in the current version.

          Here is the link:

          http://jdbforms.sourceforge.net/weekly/

          Regards,
          Henner

           
          • MisterT

            MisterT - 2005-02-17

            Ok, I just installed the latest build, but I've got the completete path again. Could you advise?

            Thanks, Theo

             
            • Henner Kollmann

              Henner Kollmann - 2005-02-17

              I will test it again!

              Henner

               
              • MisterT

                MisterT - 2005-02-18

                This would be nice.

                 
                • Henner Kollmann

                  Henner Kollmann - 2005-02-18

                  What sort of blobhandling do you use?
                  Could you post your dbforms-config definition?

                  I did a test with testDISKBLOBS.jsp from te bookstore example and everything works fine.
                  Only the filename is stored in the database.

                  Wich jsp engine doe you use?

                  Cheers,
                  Henner

                   
                  • MisterT

                    MisterT - 2005-02-19

                    I'm using a DB-based blob. The files are stored in a db-column too. The db is a MySQL 4.0. This is the definition of the table in dbforms-config.xml:

                        <table name="abc_docs"
                                    defaultVisibleFields="id" >
                            <field name="id" fieldType="int" size="11" isKey="true" autoInc="true"/>
                            <field name="name" fieldType="varchar" size="50"/>
                            <field name="docupak_id" fieldType="int" size="11" isKey="true"/>
                            <field name="is_locked" fieldType="int" size="11"/>
                            <field name="current_step_id" fieldType="int" size="11" isKey="true"/>
                            <field name="xdt_file" fieldType="blob" size="16277215"/>
                            <field name="xdt_file_name" fieldType="varchar" size="255"/>
                            <field name="tsl_file" fieldType="blob" size="16277215"/>
                            <field name="tsl_file_name" fieldType="varchar" size="255"/>
                            <field name="pf_file" fieldType="blob" size="16277215"/>
                            <field name="pf_file_name" fieldType="varchar" size="255"/>
                            <field name="pdf_file" fieldType="blob" size="16277215"/>
                            <field name="pdf_file_name" fieldType="varchar" size="255"/>
                            <field name="pdf_lock" fieldType="int" size="11"/>

                            <interceptor className="org.dbforms.event.BlobInterceptor">
                              <param name="blob-column1" value="xdt_file"/>
                              <param name="name-column1" value="xdt_file_name"/>
                              <param name="blob-column2" value="tsl_file"/>
                              <param name="name-column2" value="tsl_file_name"/>           
                              <param name="blob-column3" value="pf_file"/>
                              <param name="name-column3" value="pf_file_name"/>           
                              <param name="blob-column4" value="pdf_file"/>
                              <param name="name-column4" value="pdf_file_name"/>           
                            </interceptor>

                    I'm using the Apache Tomcat/5.0 and the JVM 1.4.2_06-b03.

                    Thanks + regards
                    Theodor

                     
                    • Henner Kollmann

                      Henner Kollmann - 2005-02-19

                      OK, never worked with the blob interceptor. Seems that it is buggy. Filename should be enough to be stored.

                      Could you change this?

                      Thanks
                      Henner

                       
                      • MisterT

                        MisterT - 2005-02-19

                        OK, I've just add a little snippet to assignBlobData() in BlobInterceptor.java:

                           private void assignBlobData(Table       table,
                                                       FieldValues fieldValues) {
                              for (Iterator iter = blobFieldData.values()
                                                                .iterator(); iter.hasNext();) {
                                 String[]   s  = (String[]) iter.next();
                                 FieldValue fv = fieldValues.get(s[BLOB_COL]);

                                 if (fv != null) {
                                    Object o = fv.getFieldValueAsObject();

                                    if ((o != null) && o instanceof FileHolder) {
                                       String fileName    = ((FileHolder) o).getFileName();
                                       int pos = fileName.lastIndexOf("\\");
                                       if (pos > 0 && pos < fileName.length() - 1)
                                       {
                                          String File = fileName.substring(pos + 1);
                                          fileName = File;
                                       }
                                       String contentType = ((FileHolder) o).getContentType();
                                       int    fileLength  = ((FileHolder) o).getFileLength();
                                       setValue(table, fieldValues, s[NAME_COL], fileName);

                                       if (s[MIME_COL] != null) {
                                          setValue(table, fieldValues, s[MIME_COL], contentType);
                                       }

                                       if (s[SIZE_COL] != null) {
                                          setValue(table, fieldValues, s[SIZE_COL],
                                                   String.valueOf(fileLength));
                                       }
                                    }
                                 }
                              }
                           }
                        }

                        Now it works

                        regards Theo

                         
                        • Henner Kollmann

                          Henner Kollmann - 2005-02-19

                          That should'nt be necessary. The fileHolder is constructed with the filename only - see MultipartRequest.MultipartRequest(...):

                                            File f = new File(fileName);
                                            // 2004-08-05-HKK/Dziugas Baltrunas:
                                            // FileItem always returns the full pathname!
                                            fileName = FileUtil.filename(f.getName());

                          I changed the code to use FileUtil.filename method - maybe that helps. Could you change and test?

                          Thanks,
                          Henner

                           
                          • MisterT

                            MisterT - 2005-02-20

                            From my point of view:
                            The programm flow definitely did not pass the code you describe if we are using the db to store the files.

                            If I write

                            fileName = "foo";

                            the whole file path was written to my db:

                                           if (!Util.isNull(fileName)) {
                                              File f = new File(fileName);
                                              //fileName = f.getName();
                                              fileName = FileUtil.filename(f.getName());
                                              // 2004-08-05-HKK/Dziugas Baltrunas:
                                              // FileItem always returns the full pathname!
                                              if ((fileName.indexOf('/') > 0) || (fileName.indexOf('\\') > 0))
                                              {
                                                 int pos;
                                                 if (fileName.lastIndexOf('\\') > fileName.lastIndexOf('/'))
                                                    pos = fileName.lastIndexOf('\\');
                                                 else
                                                    pos = fileName.lastIndexOf('/');
                                                 if (pos > 0 && pos < fileName.length() - 1)
                                                 {
                                                   fileName = fileName.substring(pos + 1);
                                                 }
                                              }
                                              // for debug purposes only:
                                              fileName = "Foo";

                            I'm not sure were in code we have to fix the problem.

                            regards Theodor

                             
                            • Henner Kollmann

                              Henner Kollmann - 2005-02-20

                              Could you try to debug where the filename is appended?

                               
                              • MisterT

                                MisterT - 2005-02-20

                                I can't find an earlier point than assignBlobData(). My suggestion is, to insert this code there:

                                            if ((o != null) && o instanceof FileHolder)
                                            {
                                               // correction for filename only:
                                               String fileName    = ((FileHolder) o).getFileName();
                                               if ((fileName.indexOf('/') > 0) || (fileName.indexOf('\\') > 0))
                                               {
                                                int pos;
                                                if (fileName.lastIndexOf('\\') > fileName.lastIndexOf('/'))
                                                   pos = fileName.lastIndexOf('\\');
                                                else
                                                   pos = fileName.lastIndexOf('/');
                                                if (pos > 0 && pos < fileName.length() - 1)
                                                {
                                                   fileName = fileName.substring(pos + 1);
                                                }
                                            }

                                regards Theo

                                 
                                • Dziugas Baltrunas

                                  Hi,

                                  sorry for maybe not following the thread exactly, but this patch was made because at least Tomcat behaved differently under win32 and Linux.

                                  What OS are you using?

                                   
                        • Henner Kollmann

                          Henner Kollmann - 2005-02-19

                          What's about building a blobinterceptor test example for the bookstore? So that we can test it?

                          Could you do this?

                          Thanks
                          Henner

                           
          • MisterT

            MisterT - 2005-02-17

            BTW: I've got an exception during an insert action with db:insertButton (dbforms v.2.5 snapshoot) in a sub form. The message is:

            Error:
            Field user_id is missing

            In the 2.4 release everything was working fine. Are there any changes with this?

            regards Theo

             
            • Henner Kollmann

              Henner Kollmann - 2005-02-17

              You must have a hidden field with the user_id inside your subform.
              See subform example!

              Henner

               
              • MisterT

                MisterT - 2005-02-18

                I've tried with and without a hidden field, but nothin helps. The message is coming.
                As long as I could see, there are examples for subforms with (bookstore) and without (all hidden fields in the dbforms distribution. My subform:
                                                <db:dbform tableName="abc_user_2_lang" maxRows="4" parentField="id"
                                                childField="user_id" autoUpdate="false" followUp="/abc_user_single.jsp">
                                                <db:header>
                                                <table cellspacing="0" align="left" bgcolor="#000000" border="0">
                                                </db:header>
                                                <db:body allowNew="false">
                                                    <tr class="clsEvenDataTableRow">
                                                        <td align="left">&nbsp;
                                                        <db:dataLabel fieldName="sprach_id">
                                                        <db:queryData name="sprach_query" query="SELECT id, sprache from abc_sprachen"/></db:dataLabel>
                                                        </td>                                       
                                                        <td align="left">&nbsp;
                                                        </td>                                       
                                                        <td align="left">
                                                        <db:deleteButton style="border:0" src="dbformslib/icons/delete.gif" alt="Eintrag lschen"
                                                        flavor="image" caption="delete" />
                                                        </td>
                                                    </tr>
                                                </db:body>
                                                <db:footer>
                                                    <tr class="clsEvenDataTableRow">
                                                        <td align="left">
                                                        <db:select fieldName="sprach_id">                                                
                                                        <db:queryData
                                                            name = "sprach_list"
                                                            query = "SELECT abc_sprachen.id, abc_sprachen.sprache FROM abc_sprachen LEFT JOIN abc_user_2_lang ON abc_sprachen.id = abc_user_2_lang.sprach_id WHERE abc_user_2_lang.sprach_id IS NULL"
                                                            disableCache="true"/>
                                                        </db:select>
                                                        </td>
                                                        <td align="left">
                                                        <db:insertButton showAlways="true" style="border:0" src="dbformslib/icons/add.gif" alt="Sprache hinzufgen"
                                                        flavor="image" caption="Sprache hinzufgen" />                                       
                                                        </td>
                                                        <td align="left">&nbsp;
                                                        </td>                                       
                                                    </tr>
                                                </table>
                                                </db:footer>
                                                </db:dbform>

                I must confess, that I'm not realy sure about the reason behind the hidden field function ;-)
                Thanks + regards theo

                 
    • Henner Kollmann

      Henner Kollmann - 2005-02-20

      OK, i just build a test page base on the bookstore example:
      testBLOBINTERCEPTOR.jsp.

      In my enviroment only the filename is stored in the database.

      IHMO it's not a good idea o change the assignBlobData method - the filename of the FileHolder is used everywhere in blobhandling to retrieve the filename.

      So we should search for the place where the fullpathname is inserted in your enviroment.

      I can't believe that you can get the fullpathname if you set the fileName hardcoded to "Foo". The fileHolder class is just an container for the filedata - nobody  changes the filename.

      What enviroment do you have? Could you send me your dbforms-config.xml and your page?

      Thanks,
      Henner Kollmann
      Henner.Kollmann@gmx.de

       
      • MisterT

        MisterT - 2005-02-21

        Hi Henner, I'm sorry, but I can't reproduce the path problem anymore.
        Now under all conditions I get the filename only in my database. The things are working as they should be. The bad news: I don't know why.

        Maybe I get confused with the different dbforms versions on my disk yesterday. Maybe there are some unstable system conditions in my environment.

        But I'm wondering how there could be a path in the interceptor field at all...

        I will try to explore it and will post my results (if there are some)  ;-)

        regards Theo

         

Log in to post a comment.

MongoDB Logo MongoDB