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 { api } from "~/utils/api";
|
||||
import axios from "axios";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
export default function VideoUploadModal() {
|
||||
const router = useRouter();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [file, setFile] = useState<File>();
|
||||
const getSignedUrl = api.video.getUploadUrl.useMutation();
|
||||
|
|
@ -24,14 +26,15 @@ export default function VideoUploadModal() {
|
|||
|
||||
const handleSubmit = async (): Promise<void> => {
|
||||
if (!file) return;
|
||||
const presignedUrl = await getSignedUrl.mutateAsync({ key: file.name });
|
||||
const { signedUrl, id } = await getSignedUrl.mutateAsync({
|
||||
key: file.name,
|
||||
});
|
||||
await axios
|
||||
.put(presignedUrl, file.slice(), {
|
||||
.put(signedUrl, file.slice(), {
|
||||
headers: { "Content-Type": file.type },
|
||||
})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
console.log("Successfully uploaded ", file.name);
|
||||
.then(() => {
|
||||
router.push("share/" + id);
|
||||
})
|
||||
.catch((err) => console.error(err));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -64,6 +64,10 @@ export const videoRouter = createTRPCRouter({
|
|||
|
||||
const signedUrl = await getSignedUrl(s3, putObjectCommand);
|
||||
|
||||
return signedUrl;
|
||||
return {
|
||||
success: true,
|
||||
id: video.id,
|
||||
signedUrl,
|
||||
};
|
||||
}),
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue