Skip to content

Commit

Permalink
Photo API fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Spytex committed Jul 24, 2023
1 parent 0fa56bd commit 2537269
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
12 changes: 7 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"cypress": "^12.17.1",
"cypress-file-upload": "^5.0.8",
"formidable": "^3.5.0",
"framer-motion": "^10.12.18",
"next": "13.4.9",
"qrcode.react": "^3.1.0",
"react": "18.2.0",
Expand Down
Binary file removed public/photos/95753308.jpg
Binary file not shown.
Binary file removed public/photos/95753309.jpg
Binary file not shown.
Binary file removed public/photos/95753313.jpg
Binary file not shown.
6 changes: 3 additions & 3 deletions src/components/ui/wagon/WagonItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const WagonItem: FC<IWagonDataSingle> = ({ Wagon }) => {
try {
const formData = new FormData();
formData.append("myImage", file);
const response = await PhotoService.uploadPhoto(Wagon.VagonNumber, formData);
console.log("File uploaded:", response.data);
await PhotoService.uploadPhoto(Wagon.VagonNumber, formData);
console.log("File uploaded:", Wagon.VagonNumber);
toast({
position: "bottom-right",
title: "File uploaded successfully.",
Expand Down Expand Up @@ -96,7 +96,7 @@ export const WagonItem: FC<IWagonDataSingle> = ({ Wagon }) => {
</Flex>
{showQRCode && (
<Center mt={4}>
<QRCode value={Wagon.VagonNumber} bgColor={bgColor} fgColor={lineColor}/>
<QRCode value={Wagon.VagonNumber} bgColor={bgColor} fgColor={lineColor} />
</Center>
)}
{showBarcode && (
Expand Down
10 changes: 8 additions & 2 deletions src/pages/api/photo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ import { HttpMethod } from '@/enums/httpMethod.enum';
import { IMiddlewareOptions } from '@/interfaces/middleware.interface';
import { Middlewares } from '@/types/middleware.type';

export const config = {
api: {
bodyParser: false,
},
};


const middlewares: Middlewares = {
[HttpMethod.POST]: postPhoto,
[HttpMethod.DELETE]: deletePhoto,
}


const readFile = (
const readFile = async (
req: NextApiRequest,
saveLocally?: boolean,
): Promise<{ fields: formidable.Fields; files: formidable.Files }> => {
Expand Down Expand Up @@ -52,7 +58,7 @@ async function postPhoto(options: IMiddlewareOptions) {
} catch (error) {
await fs.mkdir(path.join(process.cwd() + "/public", "/photos"));
}
readFile(req, true);
await readFile(req, true);
res.json({ done: "ok" });
}

Expand Down

0 comments on commit 2537269

Please sign in to comment.