瀏覽代碼

file upload try catch

Ivan Greenking 11 月之前
父節點
當前提交
47f34385cc
共有 1 個文件被更改,包括 11 次插入6 次删除
  1. 11 6
      models.js

+ 11 - 6
models.js

@@ -45,12 +45,17 @@ module.exports = async (dbName='snippet') => {
 
 
             static async fromFileData(fileData){
-                let image  = new Image({})
-                image.fileData = fileData
-                image.url      = `images/${fileData.filename}`
-                image.originalFileName = fileData.originalname
-                await image.save()
-                return image;
+		try {
+			let image  = new Image({})
+			image.fileData = fileData
+			image.url      = `images/${fileData.filename}`
+			image.originalFileName = fileData.originalname
+			await image.save()
+			return image;
+		}
+		catch(e){
+		    console.log('wrong file')
+		}
             }
 
             static get relations(){