1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

documente and implement routine in react fine uploader

This commit is contained in:
Tim Daubenschütz 2015-07-23 15:57:25 +02:00
parent 33a179cfe2
commit 80861813e9
2 changed files with 39 additions and 2 deletions

View File

@ -16,6 +16,8 @@ import GlobalNotificationActions from '../../actions/global_notification_actions
import AppConstants from '../../constants/application_constants';
import { computeHashOfFile } from '../../utils/file_utils';
var ReactS3FineUploader = React.createClass({
propTypes: {
@ -489,9 +491,44 @@ var ReactS3FineUploader = React.createClass({
GlobalNotificationActions.appendGlobalNotification(notification);
}
// As mentioned already in the propTypes declaration, in some instances we need to calculate the
// md5 hash of a file locally and just upload a txt file containing that hash.
// This if statement essentially takes care of that solution.
if(this.props.localHashing) {
// routine for adding all the files submitted to fineuploader
let convertedFilePromises = [];
// "files" is not a classical Javascript array but a Javascript FileList, therefore
// we can not use map to convert values
for(let i = 0; i < files.length; i++) {
// since the actual computation of a file's hash is an async task ,
// we're using promises to handle that
let hashedFilePromise = computeHashOfFile(files[i]);
convertedFilePromises.push(hashedFilePromise);
}
// To react after the computation of all files, we define the resolvement
// with the all function for iterables and essentially replace all original files
// with their txt representative
Promise.all(convertedFilePromises)
.then((convertedFiles) => {
// actually replacing all files with their txt-hash representative
files = convertedFiles;
})
.catch((err) => {
// if we're running into an error during the hash creation, we'll tell the user
console.logGlobal(err);
let notification = new GlobalNotificationModel(err.message, 'danger', 5000);
GlobalNotificationActions.appendGlobalNotification(notification);
});
}
// routine for adding all the files submitted to fineuploader for actual uploading them
// to the server
this.state.uploader.addFiles(files);
let oldFiles = this.state.filesToUpload;
let oldAndNewFiles = this.state.uploader.getUploads();
// Add fineuploader specific information to new files

View File

@ -50,7 +50,7 @@ export function computeHashOfFile(file) {
}.bind(this);
fileReader.onerror = function () {
reject(new Error('We weren\' able to hash your file locally. Try to upload it manually or consider contact us.'));
reject(new Error('We weren\'t able to hash your file locally. Try to upload it manually or consider contact us.'));
};
function loadNext() {