Parcourir la source

[WebApiUtils] Fixed save uploaded file

develop
Robin Thoni il y a 9 ans
Parent
révision
7c7e74416f

+ 7
- 0
WebAPiUtils-test/Controllers/ValuesController.cs Voir le fichier

@@ -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 Voir le fichier

@@ -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)

Chargement…
Annuler
Enregistrer