Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Checksum during #2139

Open
giper45 opened this issue Jul 14, 2020 · 0 comments
Open

Invalid Checksum during #2139

giper45 opened this issue Jul 14, 2020 · 0 comments

Comments

@giper45
Copy link

giper45 commented Jul 14, 2020

Hi,
I am using ng-file library to support upload of files.
I have an issue relating to binary files that is described at the following issue:
DockerSecurityPlayground/DSP#51

In order to troubleshoot, I try to log md5sum of a binary file.
When I upload a binary file, I perform the following operation:

  <div class="modal-body" id="modal-body">
    <div class="btn btn-default" ngf-select="upload($files)" ngf-multiple="true">Add File</div>
    Drop File:
    <div ngf-drop ngf-select ng-model="files" class="drop-box" 
                                              ngf-drag-over-class="'dragover'" ngf-multiple="true" ngf-include-dir="true" ngf-allow-dir="true"
                                                                                                                          >Drag and Drop file</div>
    <div ngf-no-file-drop>File Drag/Drop is not supported for this browser</div>
    <!-- Files: -->
    <!-- <ul> -->
    <!--   <li ng-repeat="f in files" style="font:smaller">{{f.name}} {{f.$error}} {{f.$errorParam}}</li> -->
    <!-- </ul> -->
    Upload Log:
    <pre>{{log}}</pre>

Controller ->

      $scope.upload = function (files) {        
        if (files && files.length) {
          for (var i = 0; i < files.length; i++) {
            var file = files[i];

            _manageUpload(file);
... 

function _manageUpload(file) {
          _getFileContent(f, function(err, data) {
   ....
}
function _getFileContent(f, cb) {
        var reader = new FileReader();
        // reader.readAsText(f, "UTF-8");
        reader.readAsBinaryString(f);
        reader.onload = function (evt) {
          var md5Hash = CryptoJS.MD5(evt.target.result);
          console.log(md5Hash.toString())
          
          cb(null, evt.target.result);
        }
        reader.onerror = function (evt) {
          cb(new Error("error reading file"));
        }
      }

}
 ... 

}

The following code outputs md5 of a file:
image

Anyway, this md5 differs from the original md5sum:
image
Wrong file is properly saved on server-side (it contains the same md5 of acquired file).
Do you have any suggestion to solve this?
Thanks in advance,
GP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant