Skip to content

Commit

Permalink
fix: preview for pdf files
Browse files Browse the repository at this point in the history
  • Loading branch information
akuokojnr committed Apr 21, 2021
1 parent 7de921a commit 576dae6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 1 addition & 3 deletions common/file-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)) {
Expand Down
13 changes: 9 additions & 4 deletions components/core/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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,
};

Expand All @@ -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);
Expand Down

0 comments on commit 576dae6

Please sign in to comment.