瀏覽代碼

[WebApiUtils] Fixed save uploaded file

develop
Robin Thoni 9 年之前
父節點
當前提交
7c7e74416f
共有 2 個檔案被更改,包括 9 行新增5 行删除
  1. 7
    0
      WebAPiUtils-test/Controllers/ValuesController.cs
  2. 2
    5
      WebApiUtils/BusinessManager/BMRHandler.cs

+ 7
- 0
WebAPiUtils-test/Controllers/ValuesController.cs 查看文件

@@ -43,5 +43,12 @@ namespace WebAPiUtils_test.Controllers
43 43
         {
44 44
             return Handle(ValuesBusiness.AddDbo(obj));
45 45
         }
46
+
47
+        [HttpPost]
48
+        [Route("api/values/upload")]
49
+        public string Upload()
50
+        {
51
+            return Handle(SaveFileToTemp().Result);
52
+        }
46 53
     }
47 54
 }

+ 2
- 5
WebApiUtils/BusinessManager/BMRHandler.cs 查看文件

@@ -76,12 +76,9 @@ namespace iiie.WebApiUtils.BusinessManager
76 76
         /// Save the uploaded file to the temp dir
77 77
         /// </summary>
78 78
         /// <returns>The file path</returns>
79
+        [NonAction]
79 80
         public async Task<OpResult<string>> SaveFileToTemp()
80 81
         {
81
-            if (!Request.Content.IsMimeMultipartContent())
82
-            {
83
-                return OpResult<string>.Error(ResultStatus.InputError, "Bad content type", "");
84
-            }
85 82
             IEnumerable<HttpContent> parts = null;
86 83
             try
87 84
             {
@@ -90,7 +87,7 @@ namespace iiie.WebApiUtils.BusinessManager
90 87
             }
91 88
             catch (Exception e)
92 89
             {
93
-                return OpResult<string>.Error(ResultStatus.InputError, e, "Failed to read uploaded file");
90
+                return OpResult<string>.Error(ResultStatus.InputError, e, "Failed to read post parts (maximum size exceeded?)");
94 91
             }
95 92
             HttpContent file = parts.FirstOrDefault();
96 93
             if (file == null)

Loading…
取消
儲存