Skip to content

Commit

Permalink
FIO-4836: hash was added to file (formio#4682)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria-Golomb authored Apr 21, 2022
1 parent 2d2d449 commit 5400b3a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@formio/vanilla-text-mask": "^5.1.1",
"autocompleter": "^6.1.2",
"browser-cookies": "^1.2.0",
"browser-md5-file": "^1.1.1",
"compare-versions": "^4.1.3",
"core-js": "^3.21.1",
"custom-event-polyfill": "^1.0.7",
Expand Down
12 changes: 12 additions & 0 deletions src/components/file/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import download from 'downloadjs';
import _ from 'lodash';
import NativePromise from 'native-promise-only';
import fileProcessor from '../../providers/processor/fileProcessor';
import BMF from 'browser-md5-file';

let Camera;
let webViewCamera = navigator.camera || Camera;
Expand Down Expand Up @@ -612,13 +613,23 @@ export default class FileComponent extends Field {
// files is not really an array and does not have a forEach method, so fake it.
/* eslint-disable max-statements */
Array.prototype.forEach.call(files, async(file) => {
const bmf = new BMF();
const hash = await new Promise((resolve, reject) => {
bmf.md5(file, (err, md5)=>{
if (err) {
return reject(err);
}
return resolve(md5);
});
});
const fileName = uniqueName(file.name, this.component.fileNameTemplate, this.evalContext());
const fileUpload = {
originalName: file.name,
name: fileName,
size: file.size,
status: 'info',
message: this.t('Processing file. Please wait...'),
hash
};

// Check if file with the same name is being uploaded
Expand Down Expand Up @@ -756,6 +767,7 @@ export default class FileComponent extends Field {
this.statuses.splice(index, 1);
}
fileInfo.originalName = file.name;
fileInfo.hash = fileUpload.hash;
if (!this.hasValue()) {
this.dataValue = [];
}
Expand Down

0 comments on commit 5400b3a

Please sign in to comment.