Browse Source

[WebApiUtils] Fixed save uploaded file

develop
Robin Thoni 9 years ago
parent
commit
7c7e74416f

+ 7
- 0
WebAPiUtils-test/Controllers/ValuesController.cs View File

43
         {
43
         {
44
             return Handle(ValuesBusiness.AddDbo(obj));
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 View File

76
         /// Save the uploaded file to the temp dir
76
         /// Save the uploaded file to the temp dir
77
         /// </summary>
77
         /// </summary>
78
         /// <returns>The file path</returns>
78
         /// <returns>The file path</returns>
79
+        [NonAction]
79
         public async Task<OpResult<string>> SaveFileToTemp()
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
             IEnumerable<HttpContent> parts = null;
82
             IEnumerable<HttpContent> parts = null;
86
             try
83
             try
87
             {
84
             {
90
             }
87
             }
91
             catch (Exception e)
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
             HttpContent file = parts.FirstOrDefault();
92
             HttpContent file = parts.FirstOrDefault();
96
             if (file == null)
93
             if (file == null)

Loading…
Cancel
Save