mirror of
https://github.com/outline/outline.git
synced 2026-11-25 07:04:37 +03:00
fix: Avatar uploads send an undefined file name (#14367)
This commit is contained in:
1 parent
0d61a3e68b
commit
d3b0943527
1 file changed
+14
-8
@@ -7,6 +7,7 @@ import { useDropzone } from "react-dropzone";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import { errToString } from "@shared/utils/error";
|
||||
import { dataUrlToFile } from "@shared/utils/files";
|
||||
import { s } from "@shared/styles";
|
||||
import { AttachmentPreset } from "@shared/types";
|
||||
import { AttachmentValidation } from "@shared/validations";
|
||||
@@ -14,7 +15,7 @@ import ButtonLarge from "~/components/ButtonLarge";
|
||||
import Flex from "~/components/Flex";
|
||||
import LoadingIndicator from "~/components/LoadingIndicator";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { uploadFile, dataUrlToBlob, toDropzoneAccept } from "~/utils/files";
|
||||
import { uploadFile, extname, toDropzoneAccept } from "~/utils/files";
|
||||
import { ImageHelper } from "~/utils/ImageHelper";
|
||||
|
||||
export type Props = {
|
||||
@@ -39,14 +40,13 @@ const ImageUpload: React.FC<Props> = ({
|
||||
const [isConverting, setIsConverting] = useState(false);
|
||||
|
||||
const uploadImage = React.useCallback(
|
||||
async (blob: Blob, file: File) => {
|
||||
async (file: File) => {
|
||||
try {
|
||||
const compressed = await ImageHelper.compress(blob, {
|
||||
const compressed = await ImageHelper.compress(file, {
|
||||
maxHeight: 512,
|
||||
maxWidth: 512,
|
||||
});
|
||||
const attachment = await uploadFile(compressed, {
|
||||
name: file.name,
|
||||
preset: AttachmentPreset.Avatar,
|
||||
});
|
||||
void onSuccess(attachment.url);
|
||||
@@ -61,8 +61,8 @@ const ImageUpload: React.FC<Props> = ({
|
||||
);
|
||||
|
||||
const handleUpload = React.useCallback(
|
||||
(blob: Blob, file: File) => {
|
||||
void uploadImage(blob, file);
|
||||
(file: File) => {
|
||||
void uploadImage(file);
|
||||
},
|
||||
[uploadImage]
|
||||
);
|
||||
@@ -130,7 +130,7 @@ const ImageUpload: React.FC<Props> = ({
|
||||
|
||||
type AvatarEditorDialogProps = {
|
||||
file: File;
|
||||
onUpload: (blob: Blob, file: File) => void;
|
||||
onUpload: (file: File) => void;
|
||||
borderRadius: number;
|
||||
submitText: string;
|
||||
};
|
||||
@@ -150,7 +150,13 @@ const AvatarEditorDialog: React.FC<AvatarEditorDialogProps> = observer(
|
||||
setTimeout(() => {
|
||||
const canvas = avatarEditorRef.current?.getImage();
|
||||
invariant(canvas, "canvas is not defined");
|
||||
onUpload(dataUrlToBlob(canvas.toDataURL()), file);
|
||||
|
||||
// The canvas exports PNG, so the name must have a matching extension.
|
||||
const basename = file.name.slice(
|
||||
0,
|
||||
file.name.length - extname(file.name).length
|
||||
);
|
||||
onUpload(dataUrlToFile(canvas.toDataURL(), `${basename}.png`));
|
||||
}, 0);
|
||||
}, [file, onUpload]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user