From 576dae6c79d5b313c82269285c1859280c1a3bb1 Mon Sep 17 00:00:00 2001 From: Akuoko Daniel Jnr Date: Wed, 21 Apr 2021 05:22:19 +0000 Subject: [PATCH] fix: preview for pdf files --- common/file-utilities.js | 4 +--- components/core/Application.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/common/file-utilities.js b/common/file-utilities.js index c563bd226..2214ca143 100644 --- a/common/file-utilities.js +++ b/common/file-utilities.js @@ -73,10 +73,8 @@ export const upload = async ({ }); //TODO(martina): figure out how to cancel an await if upload has been cancelled formData.append(fileId, converted); - } else if (file.type.startsWith("image")) { - formData.append(fileId, file); } else { - formData.append("data", file); + formData.append(fileId, file); } if (Store.checkCancelled(`${file.lastModified}-${file.name}`)) { diff --git a/components/core/Application.js b/components/core/Application.js index 5c71ea995..a1a9ffaaa 100644 --- a/components/core/Application.js +++ b/components/core/Application.js @@ -441,9 +441,9 @@ export default class ApplicationPage extends React.Component { _handleOptimisticUpload = async ({ files }) => { let optimisticFiles = []; for (let i = 0; i < files.length; i++) { - if (!files[i].type.startsWith("image")) { - continue; - } + // if (!files[i].type.startsWith("image") || !files[i].type.startsWith("video")) { + // continue; + // } let id = `data-${uuid()}`; let dataURL = await this._handleLoadDataURL(files[i]); @@ -452,7 +452,7 @@ export default class ApplicationPage extends React.Component { name: files[i].name, type: files[i].type, size: files[i].size, - decorator: "OPTIMISTIC-IMAGE-FILE", + decorator: "OPTIMISTIC-FILE", dataURL, }; @@ -473,6 +473,11 @@ export default class ApplicationPage extends React.Component { _handleLoadDataURL = (file) => new Promise((resolve, reject) => { + if (file.type.startsWith("application/pdf")) { + resolve(URL.createObjectURL(file)); + return; + } + const reader = new FileReader(); reader.onload = () => { resolve(reader.result);