简体   繁体   English

区块链Tierion API-使用Node.js实时上传文件

[英]Blockchain Tierion API - Real time File upload using Node.js

Subject: Real time file upload using Node.js 主题:使用Node.js实时上传文件

Hi all, I am working on real file upload using Node.js and i am facing the error in below mentioned code: 大家好,我正在使用Node.js进行实际文件upload并且Node.js以下代码中的错误:

function handleFile(files) {
        if (!files.length) {
            return;
        }
        var file = files[0];

        var reader = new FileReader();
        reader.readAsArrayBuffer(file);
        reader.onprogress = function (e) {
            dragZone.removeClass( 'is-uploading' );
            dragZone.removeClass( 'is-error' );
            dragZone.addClass( 'is-success' );
            if (e.lengthComputable) {
                var percentComplete = (e.loaded / e.total)*100;
                percentComplete = parseInt(percentComplete);
                //Do something with upload progress
                console.log(percentComplete);
                $('#status').text(percentComplete+'%');
                $('.progress-bar').text(percentComplete+'%');
                $('#progressBar').val(percentComplete);
                //console.log(e.loaded+  " / " + e.total)
            }
        }

        reader.onload = function(e) {
            var data = e.target.result;
            //Error-facing
            window.crypto.subtle.digest({name: 'SHA-256'}, data).then(function(hash) {
                var hexString = '';
                var bytes = new Uint8Array(hash);

                for (var i = 0; i < bytes.length; i++) {
                    var hex_i = bytes[i].toString(16);
                    hexString += hex_i.length === 1 ? '0' + hex_i : hex_i;
                }

                $('#hash').text(hexString);
                calculatedHash = hexString;

                dragZone.removeClass( 'is-uploading' );
                dragZone.removeClass( 'is-error' );
                dragZone.addClass( 'is-success' );
            }).catch(function(e) {
                showError(e);
            });
        };

Anybody please guide me how to resolve this error: 有人请指导我如何解决此错误:

index.js:138 Uncaught TypeError: Cannot read property 'digest' of undefined
    at FileReader.reader.onload

There is no data passing to this hash variable below mentioned line: 在提到的行下面没有数据传递到此哈希变量:

window.crypto.subtle.digest({name: 'SHA-256'}, data).then(function(hash)

I presume you use this on a site with http? 我想您在带有http的网站上使用它吗? the crypto api is not available on insecure domains, you need to use https for digest to work crypto api在不安全的域上不可用,您需要使用https进行摘要才能工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM