1

I need to pass the path of the selected file in the createReadStream (path_to_file.pdf) place. How am I supposed to do this, I have looked at the primefaces docs and I can't make anything meaningful

import {useRef} from "react";
import {Toast} from "primereact/toast";
import {FileUpload} from "primereact/fileupload";
import {Tooltip} from "primereact/tooltip";


export const FileUploadCv = () => {
  const toast = useRef(null);
  const {AffindaCredential, AffindaAPI} = require("@affinda/affinda");
  const fs = require("fs");
  const credential = new AffindaCredential("token")
  const client = new AffindaAPI(credential)

  const onUpload = () => {
    toast.current.show({severity: 'info', summary: 'Success', detail: 'File Uploaded'});
    const readStream = fs.createReadStream("path_to_file.pdf");

    client.createResume({file: readStream}).then((result) => {
        console.log("Returned data:");
        console.dir(result)
    }).catch((err) => {
        console.log("An error occurred:");
        console.error(err);
    });
  }

  return (
    <div>
      <Toast ref={toast}></Toast>
      <Tooltip target=".custom-choose-btn" content="Choose" position="bottom" />
      <Tooltip target=".custom-upload-btn" content="Upload" position="bottom" />
      <Tooltip target=".custom-cancel-btn" content="Clear" position="bottom" />
      <button onClick={onUpload}>simea</button>
      <div className="card">
        <FileUpload
          name="demo[]"
          url="https://api.affinda.com/v2"
          onUpload={onUpload}
          multiple
          accept=".pdf, .doc, .docx "
          emptyTemplate={<p className="m-0">Drag and drop files to here to upload.</p>}
        />
      </div>
    </div>
  );
};
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102

1 Answers1

1

The method onUpload has this signature..

 onUpload?(e: FileUploadUploadParams): void;

Which gives you access to the array of files because the event looks like this...

interface FileUploadUploadParams  {
    xhr: XMLHttpRequest;
    files: File[];
}
Melloware
  • 10,435
  • 2
  • 32
  • 62