3 Replies Latest reply on Jan 7, 2015 10:07 AM by Horia Chiorean

    Hash-generation for uploaded file (upload via WebDAV)

    Jürgen Baier Newbie

      Hello,

       

      I would like to generate a hash for each file (from its content) that is uploaded via WebDAV and attach it to the file-node as property. That allows me to easily check if remote files are identical to the ones on the server by calculating their hash remotely and comparing it to the one on the server. Is there a recommended way to achieve this hash-calculation and -adding while uploading? Has anybody tried something similar yet?

       

      Regards,

      Juergen

        • 1. Re: Hash-generation for uploaded file (upload via WebDAV)
          Horia Chiorean Master

          I don't think anyone has tried this yet, but in theory it should be possible: when interacting via WebDAV, by default, ModeShape uses the nt:file, nt:folder & nt:resource node types to represent the data. So the first thing you would have to do is create you own custom node type which extends nt:file and defines your hash property. After that, you need to configure/overwrite the following parameter from the ModeShape's WebDAV webapp web.xml:

              <context-param>

                  <param-name>org.modeshape.web.jcr.webdav.NEW_RESOURCE_PRIMARY_TYPE_NAME</param-name>

                  <param-value>your_type</param-value>

              </context-param>

          See ModeShape's WebDAV Service - ModeShape 4 - Project Documentation Editor for a list of all context params.

           

          Once your custom web.xml is overlaying (overwriting) the default one, whenever you create new resources via WebDAV they should have your own custom type. This means that setting the hash property would be a 2-step process:

          1. create the new file (resource) - which should now have your custom type

          2. issue a PROPPATCH with the value for the property

          1 of 1 people found this helpful
          • 2. Re: Hash-generation for uploaded file (upload via WebDAV)
            Jürgen Baier Newbie

            Thank you for the quick response! For step 1 everything should be clear so far... great!


            For step 2: If I would like to calculate+add the hash on the server-side (e.q. to detect transfer errors), do you know where I can get access to the content-stream to do so?

            • 3. Re: Hash-generation for uploaded file (upload via WebDAV)
              Horia Chiorean Master

              For step 2: If I would like to calculate+add the hash on the server-side (e.q. to detect transfer errors), do you know where I can get access to the content-stream to do so?

              If by this you mean some sort of "hook" that you can "program" so that when you save something via WebDAV you can modify data on the server, there is no such API. The WebDAV support is limited to files/folders & the default WebDAV methods (as issued by a WebDAV compliant client).

              If this question is unrelated to WebDAV, ModeShape's API provides methods for retrieving the SHA-1 of a binary value via this interface: modeshape/Binary.java at modeshape-4.1.0.Final · ModeShape/modeshape · GitHub. So outside of WebDAV, any JCR sever-code can retrieve the binary from an nt:file and then use this interface or just read the bytes[] and do whatever calculation it wants.