Skip to content

Commit

Permalink
fixed/resume-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutoshpadhi629 committed Oct 12, 2024
1 parent c420902 commit afc9af0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/actions/upload-to-cdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import { v4 as uuidv4 } from 'uuid';

export async function uploadFileAction(formData: FormData) {
type FileType = 'webp' | 'pdf';

export async function uploadFileAction(formData: FormData, fileType: FileType) {
const CDN_BASE_UPLOAD_URL = process.env.CDN_BASE_UPLOAD_URL!;
const CDN_BASE_ACCESS_URL = process.env.CDN_BASE_ACCESS_URL!;
const CDN_API_KEY = process.env.CDN_API_KEY!;
Expand All @@ -14,7 +16,7 @@ export async function uploadFileAction(formData: FormData) {
if (!file) {
return { error: 'File is required', status: 400 };
}
const uploadUrl = `${CDN_BASE_UPLOAD_URL}/${uniqueFileName}.webp`;
const uploadUrl = `${CDN_BASE_UPLOAD_URL}/${uniqueFileName}.${fileType}`;
const fileBuffer = Buffer.from(await file.arrayBuffer());

const response = await fetch(uploadUrl, {
Expand All @@ -28,7 +30,7 @@ export async function uploadFileAction(formData: FormData) {
if (response.ok) {
return {
message: 'File uploaded successfully',
url: `${CDN_BASE_ACCESS_URL}/${uniqueFileName}.webp`,
url: `${CDN_BASE_ACCESS_URL}/${uniqueFileName}.${fileType}`,
};
} else {
return { error: 'Failed to upload file', status: response.status };
Expand Down
4 changes: 2 additions & 2 deletions src/components/job-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const PostJobForm = () => {
useEffect(() => {
if (session.status !== 'loading' && session.status === 'unauthenticated')
router.push(`${APP_PATHS.SIGNIN}?redirectTo=/create`);
}, [session.status]);
}, [session.status, router]);

const { toast } = useToast();
const companyLogoImg = useRef<HTMLImageElement>(null);
Expand Down Expand Up @@ -116,7 +116,7 @@ const PostJobForm = () => {
const uniqueFileName = `${Date.now()}-${file.name}`;
formData.append('uniqueFileName', uniqueFileName);

const res = await uploadFileAction(formData);
const res = await uploadFileAction(formData, 'webp');
if (!res) {
throw new Error('Failed to upload image');
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/user-multistep-form/add-resume-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const AddResume = () => {
const uniqueFileName = `${Date.now()}-${file.name}`;
formData.append('uniqueFileName', uniqueFileName);

const res = await uploadFileAction(formData);
const res = await uploadFileAction(formData, 'pdf');
if (!res) {
return toast({
title: 'Internal Server Error',
Expand Down

0 comments on commit afc9af0

Please sign in to comment.