3 Replies Latest reply on Apr 25, 2008 2:08 PM by buabco

    Need to get MD5 hash of bytes in a file

    flashharry! Level 1

      I need to create a finger print of a file, I would do this with an MD5 hash. On OSX you can open the terminal type md5 then drag a file to the terminal window and it will give you the finger print I want.

      I have the md5 hash from http://gsolofp.blogspot.com/2006/01/actionscript-3-md5-and-sha1.html
      Great work and makes a md5 hash of a string.

      Using a file reference how would I get that back as a MD% hash. Thoughts are if I could load it in to byte array then user array to string.

      Any ideas on how to load a file reference in to a byte array.

      Thanks in advance
        • 1. Re: Need to get MD5 hash of bytes in a file
          flashharry! Level 1
          Ok with the help of some AS from
          http://www.lynchconsulting.com.au/blog/index.cfm/2008/1/25/MD5-Checksum-for-Images-Binarie s-in-Actionscript

          I'm 95% there, need help with last hurdle.

          Present the user with a file browse, the user selects the file. We now have the file in the file reference. I can get name, creator size but not the path.
          The user selected the path, why can I not get to the path. I get the security sandbox thing but HEY the user just said I can have the file and upload it (his giving it too me), but I don't want to upload it. I just want the hash.

          Ok, I don't need to know the path, but flex does as it knows where to grab the file to upload it, so how to I tell flex where to get it using a url loader.

          This code works, but I hard coded the path for testing, how can I load the file with out hard coding my test path.

          Remember this works, but how do I do this URLRequest('file:///Library/ColorSync/Profiles/' + event.target.name);

          with the file reference path. I don't need r care to know the path, but I do need to load it locally.

          Thanks in advance

          private function onSelectFile(event:Event):void {
          var urlReq:URLRequest =new URLRequest('file:///Library/ColorSync/Profiles/' + event.target.name);
          var uLdr:URLLoader = new URLLoader();
          uLdr.dataFormat = URLLoaderDataFormat.BINARY;
          private function imageLoadHandler(e:Event):void{
          trace('Image Loaded');
          var rawFile:ByteArray = e.currentTarget.data;

          • 2. Re: Need to get MD5 hash of bytes in a file
            flashharry! Level 1
            Adobe take note:
            The sandbox rules are two restrictive, the user as given us the file by selecting it, but rather than upload the file I and many many others would like to load it into the SWF. I don't need to know about the users file system, I don't need to know the path. If I can upload the file, why can I not just load it directly into the swf.

            I now have to upload the file, process the file in PHP and then either accept the file which is fine, or tell the user that this file is already in the system and we can not accept. Sorry too have wasted your time and bandwidth but we at too upload it first to reject. Please try again with another file.

            Come on, we should be able to load a copy of the file.

            var urlReq:URLRequest =new URLRequest(fileReference);

            With out breaking any sandbox. Its upload to the swf not the server, what is the difference.?

            Frustrated spent two days trying to get this to work

            • 3. Re: Need to get MD5 hash of bytes in a file
              I totally agree, in my case I want to upload files to the server that need to be preprocessed first by the SWF.

              For example, what if a user wants to upload a picture (lets say a portrait that will be use as his image in a forum) but the site only accept pictures of a certain size, so before the picture is uploaded, the user might want to have the chance to crop and resize the image to fit the size, its extremely stupid to have to upload the image to the server, then download the image into the SWF so the SWF will have it and do this kind of processing. And then when the user is ready with his image, a third upload will be needed to finally get the image to the servers database.