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

MD5 error #1

Open
zzj0402 opened this issue Oct 22, 2019 · 1 comment
Open

MD5 error #1

zzj0402 opened this issue Oct 22, 2019 · 1 comment

Comments

@zzj0402
Copy link

zzj0402 commented Oct 22, 2019

Environment

OS

elementary OS 5.0 Juno

Angular

Angular CLI: 8.3.12
Node: 12.12.0
OS: linux x64
Angular: 8.0.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.3
@angular-devkit/build-angular     0.800.3
@angular-devkit/build-optimizer   0.800.3
@angular-devkit/build-webpack     0.800.3
@angular-devkit/core              8.0.3
@angular-devkit/schematics        8.3.12
@angular/cdk                      8.1.1
@angular/cli                      8.3.12
@angular/flex-layout              8.0.0-beta.26
@angular/material                 8.1.1
@ngtools/webpack                  8.0.3
@schematics/angular               8.3.12
@schematics/update                0.803.12
rxjs                              6.4.0
typescript                        3.4.5
webpack                           4.30.0

Browser

Chrome
Version 77.0.3865.120 (Official Build) (64-bit)

html template

  <form enctype="multipart/form-data" method="post">
    <div>
      <label for="picked">ARFF dataset</label>
      <div>
        <input
          type="file"
          id="picked"
          #picked
          (click)="message = ''"
          (change)="onPicked(picked)"
        />
      </div>
    </div>
  </form>

controller ts

import { Component } from "@angular/core";
import { UploaderService } from "./uploader.service";
import { global } from "../global";
import { md5 } from "./md5";
@Component({
  selector: "app-uploader",
  templateUrl: "./uploader.component.html",
  providers: [UploaderService]
})
export class UploaderComponent {
  message: string = "Please upload an .arff file!";
  constructor(private uploaderService: UploaderService) {}
  userID: string = null;
  onPicked(input: HTMLInputElement) {
    const file = input.files[0];

    if (file) {
      const fileMD5 = md5(file);
      console.log("File MD5" + fileMD5);
      let fileExtension = file.name.split(".").pop();
      // console.log(fileExtension);
      if (fileExtension != "arff" && fileExtension != "ARFF") {
        this.message = "File error! Please provide a valid arff file!";
        console.error("File extension error!");
      } else {
        this.uploaderService.upload(file).subscribe(msg => {
          input.value = null;
          this.message = msg;
          this.userID = global.userID;
        });
      }
    }
  }
}
UploaderComponent.html:12 ERROR TypeError: string.replace is not a function
    at Utf8Encode (md5.ts:102)
    at md5 (md5.ts:144)
    at UploaderComponent.onPicked (uploader.component.ts:18)
    at Object.eval [as handleEvent] (UploaderComponent.html:17)
    at handleEvent (core.js:34789)
    at callWithDebugContext (core.js:36407)
    at Object.debugHandleEvent [as handleEvent] (core.js:36043)
    at dispatchEvent (core.js:22533)
    at core.js:33721
    at HTMLInputElement.<anonymous> (platform-browser.js:1789)
@zzj0402
Copy link
Author

zzj0402 commented Oct 22, 2019

Fixed by following https://stackoverflow.com/questions/4775206/var-replace-is-not-a-function
change from string = string.replace(/\r\n/g, "\n"); to string = string.toString().replace(/\r\n/g, "\n");

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