feat: Compress avatar images before upload (#1751)

* compress avatar images before upload

* move compressImage to dedicated file

* Update ImageUpload.js
This commit is contained in:
Gustavo Maronato
2020-12-29 02:08:10 -03:00
committed by GitHub
parent b6ab816bb3
commit 89903b4bbe
4 changed files with 42 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import Button from "components/Button";
import Flex from "components/Flex";
import LoadingIndicator from "components/LoadingIndicator";
import Modal from "components/Modal";
import { compressImage } from "utils/compressImage";
import { uploadFile, dataUrlToBlob } from "utils/uploadFile";
const EMPTY_OBJECT = {};
@ -53,7 +54,11 @@ class ImageUpload extends React.Component<Props> {
const canvas = this.avatarEditorRef.getImage();
const imageBlob = dataUrlToBlob(canvas.toDataURL());
try {
const attachment = await uploadFile(imageBlob, {
const compressed = await compressImage(imageBlob, {
maxHeight: 512,
maxWidth: 512,
});
const attachment = await uploadFile(compressed, {
name: this.file.name,
public: true,
});