diff --git a/routes/upload.js b/routes/upload.js index 51a7c49..cce099a 100644 --- a/routes/upload.js +++ b/routes/upload.js @@ -37,7 +37,13 @@ router.post('/upLoadDoc',uploaddemo, async (ctx, next) => { category:category, path:'http://localhost:10000/'+ctx.req.file.originalname } - let attachment = await attachmentModel.create(attachmentData) + let oldAttachment = await attachmentModel.findOne({where:{businessId:businessId}}) + + if(oldAttachment){ + let oldAttachment = await attachmentModel.update({path:'http://localhost:10000/'+ctx.req.file.originalname},{where:{businessId:businessId}}) + }else{ + let attachment = await attachmentModel.create(attachmentData) + } ctx.response.status= 200; ctx.body = { fileUrl:'http://localhost:10000/'+ctx.req.file.originalname diff --git a/views/index.html b/views/index.html index cabf04b..fe10011 100644 --- a/views/index.html +++ b/views/index.html @@ -7,7 +7,7 @@ <script src="http://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script> </head> <body> - <form action="/upload/upLoadDoc?businessId=1&category=1" method="post" enctype="multipart/form-data"> + <form action="/upload/upLoadDoc?businessId=0aJeQOYgLAo5yB1mE14Rvzb69V7mpZKD&category=1" method="post" enctype="multipart/form-data"> <input type="file" name="file"/> <input type="text" value="1212" name="class" > <input type="submit" value="ok"/>