Browse Source

preview and download other types of file

FE_dev
Dzenis Hadzifejzovic 3 years ago
parent
commit
8d7ccf2185
1 changed files with 21 additions and 6 deletions
  1. 21
    6
      src/pages/FilesPage/FilesViewPage.js

+ 21
- 6
src/pages/FilesPage/FilesViewPage.js View File

console.log(e, "error in file-viewer"); console.log(e, "error in file-viewer");
}; };


const displayFile = (fileStream, streamId) => {
setFile({ fileStream, streamId });
const displayFile = (fileStream, streamId, fileType) => {
setFile({ fileStream, streamId, fileType });
}; };

const getHrefForDownload = (fileType, fileStream) => {
if (fileType === "docx") {
return `data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,${fileStream}`;
} else if (fileType === "doc") {
return `data:application/msword;base64,${fileStream}`;
} else {
return `data:application/pdf;base64,${fileStream}`;
}
};

return isLoading ? ( return isLoading ? (
<div> <div>
<div className="l-t-rectangle"></div> <div className="l-t-rectangle"></div>
<tr <tr
key={index} key={index}
className="secondaryRow" className="secondaryRow"
onClick={() => displayFile(n.file_stream, n.stream_id)}
onClick={() =>
displayFile(n.file_stream, n.stream_id, n.file_type)
}
> >
<td className="docs-name">{n.fileName}</td> <td className="docs-name">{n.fileName}</td>
<td className="docs-name">{n.title}</td> <td className="docs-name">{n.title}</td>
padding: 8, padding: 8,
}} }}
download={n.title} download={n.title}
href={`data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,${n.file_stream}`}
href={getHrefForDownload(
n.file_type,
n.file_stream
)}
> >
{t("common.download")} {t("common.download")}
</a> </a>
}} }}
> >
<FileViewer <FileViewer
fileType="docx"
fileType={file.fileType}
filePath={`data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,${file.fileStream}`} filePath={`data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,${file.fileStream}`}
onError={onError} onError={onError}
/> />

Loading…
Cancel
Save