redirect to video page after upload
This commit is contained in:
parent
2c762f6d4f
commit
5ce820d5c4
2 changed files with 13 additions and 6 deletions
|
|
@ -2,8 +2,10 @@ import { type ChangeEvent, Fragment, useState } from "react";
|
||||||
import { Dialog, Transition } from "@headlessui/react";
|
import { Dialog, Transition } from "@headlessui/react";
|
||||||
import { api } from "~/utils/api";
|
import { api } from "~/utils/api";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
export default function VideoUploadModal() {
|
export default function VideoUploadModal() {
|
||||||
|
const router = useRouter();
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [file, setFile] = useState<File>();
|
const [file, setFile] = useState<File>();
|
||||||
const getSignedUrl = api.video.getUploadUrl.useMutation();
|
const getSignedUrl = api.video.getUploadUrl.useMutation();
|
||||||
|
|
@ -24,14 +26,15 @@ export default function VideoUploadModal() {
|
||||||
|
|
||||||
const handleSubmit = async (): Promise<void> => {
|
const handleSubmit = async (): Promise<void> => {
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
const presignedUrl = await getSignedUrl.mutateAsync({ key: file.name });
|
const { signedUrl, id } = await getSignedUrl.mutateAsync({
|
||||||
|
key: file.name,
|
||||||
|
});
|
||||||
await axios
|
await axios
|
||||||
.put(presignedUrl, file.slice(), {
|
.put(signedUrl, file.slice(), {
|
||||||
headers: { "Content-Type": file.type },
|
headers: { "Content-Type": file.type },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then(() => {
|
||||||
console.log(response);
|
router.push("share/" + id);
|
||||||
console.log("Successfully uploaded ", file.name);
|
|
||||||
})
|
})
|
||||||
.catch((err) => console.error(err));
|
.catch((err) => console.error(err));
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,10 @@ export const videoRouter = createTRPCRouter({
|
||||||
|
|
||||||
const signedUrl = await getSignedUrl(s3, putObjectCommand);
|
const signedUrl = await getSignedUrl(s3, putObjectCommand);
|
||||||
|
|
||||||
return signedUrl;
|
return {
|
||||||
|
success: true,
|
||||||
|
id: video.id,
|
||||||
|
signedUrl,
|
||||||
|
};
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue