@@ -69,16 +69,20 @@ The <a href="https://www.telerik.com/blazor-ui/upload" target="_blank">Blazor Up
6969 try
7070 {
7171 var fileContent = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
72-
72+
7373 // Some browsers send file names with full path.
7474 // We are only interested in the file name.
7575 var fileName = Path.GetFileName(fileContent.FileName.ToString().Trim('"'));
76+
77+ // server Blazor app
7678 var physicalPath = Path.Combine(HostingEnvironment.WebRootPath, fileName);
77-
79+ // client Blazor app
80+ //var physicalPath = Path.Combine(HostingEnvironment.ContentRootPath, fileName);
81+
7882 // Implement security mechanisms here - prevent path traversals,
7983 // check for allowed extensions, types, size, content, viruses, etc.
8084 // This sample always saves the file to the root and is not sufficient for a real application.
81-
85+
8286 using (var fileStream = new FileStream(physicalPath, FileMode.Create))
8387 {
8488 await file.CopyToAsync(fileStream);
@@ -91,12 +95,11 @@ The <a href="https://www.telerik.com/blazor-ui/upload" target="_blank">Blazor Up
9195 await Response.WriteAsync("some error message"); // custom error message
9296 }
9397 }
94-
98+
9599 // Return an empty string message in this case
96100 return new EmptyResult();
97101 }
98-
99-
102+
100103 [HttpPost]
101104 public ActionResult Remove(string fileToRemove) // must match RemoveField which defaults to "files"
102105 {
@@ -105,11 +108,12 @@ The <a href="https://www.telerik.com/blazor-ui/upload" target="_blank">Blazor Up
105108 try
106109 {
107110 var fileName = Path.GetFileName(fileToRemove);
111+
108112 // server Blazor app
109113 var physicalPath = Path.Combine(HostingEnvironment.WebRootPath, fileName);
110114 // client Blazor app
111115 //var physicalPath = Path.Combine(HostingEnvironment.ContentRootPath, fileName);
112-
116+
113117 if (System.IO.File.Exists(physicalPath))
114118 {
115119 // Implement security mechanisms here - prevent path traversals,
@@ -126,7 +130,7 @@ The <a href="https://www.telerik.com/blazor-ui/upload" target="_blank">Blazor Up
126130 Response.WriteAsync("some error message"); // custom error message
127131 }
128132 }
129-
133+
130134 // Return an empty string message in this case
131135 return new EmptyResult();
132136 }
@@ -258,8 +262,12 @@ The Upload methods are accesible through its [reference](#upload-reference).
258262 // Some browsers send file names with full path.
259263 // We are only interested in the file name.
260264 var fileName = Path.GetFileName(fileContent.FileName.ToString().Trim('"'));
261- var physicalPath = Path.Combine(HostingEnvironment.WebRootPath, fileName);
262-
265+
266+ // server Blazor app
267+ //var physicalPath = Path.Combine(HostingEnvironment.WebRootPath, fileName);
268+ // client Blazor app
269+ var physicalPath = Path.Combine(HostingEnvironment.ContentRootPath, fileName);
270+
263271 // Implement security mechanisms here - prevent path traversals,
264272 // check for allowed extensions, types, size, content, viruses, etc.
265273 // This sample always saves the file to the root and is not sufficient for a real application.
@@ -276,12 +284,11 @@ The Upload methods are accesible through its [reference](#upload-reference).
276284 await Response.WriteAsync("some error message"); // custom error message
277285 }
278286 }
279-
287+
280288 // Return an empty string message in this case
281289 return new EmptyResult();
282290 }
283-
284-
291+
285292 [HttpPost]
286293 public ActionResult Remove(string fileToRemove) // must match RemoveField which defaults to "files"
287294 {
@@ -290,17 +297,18 @@ The Upload methods are accesible through its [reference](#upload-reference).
290297 try
291298 {
292299 var fileName = Path.GetFileName(fileToRemove);
300+
293301 // server Blazor app
294- var physicalPath = Path.Combine(HostingEnvironment.WebRootPath, fileName);
302+ // var physicalPath = Path.Combine(HostingEnvironment.WebRootPath, fileName);
295303 // client Blazor app
296- // var physicalPath = Path.Combine(HostingEnvironment.ContentRootPath, fileName);
304+ var physicalPath = Path.Combine(HostingEnvironment.ContentRootPath, fileName);
297305
298306 if (System.IO.File.Exists(physicalPath))
299307 {
300308 // Implement security mechanisms here - prevent path traversals,
301309 // check for allowed extensions, types, permissions, etc.
302310 // this sample always deletes the file from the root and is not sufficient for a real application.
303-
311+
304312 System.IO.File.Delete(physicalPath);
305313 }
306314 }
@@ -311,7 +319,7 @@ The Upload methods are accesible through its [reference](#upload-reference).
311319 Response.WriteAsync("some error message"); // custom error message
312320 }
313321 }
314-
322+
315323 // Return an empty string message in this case
316324 return new EmptyResult();
317325 }
@@ -347,4 +355,3 @@ Cross-origin requests depend on the application and endpoint setup. The `WidthCr
347355 * [ Events] ({%slug upload-events%})
348356 * [ Validation] ({%slug upload-validation%})
349357 * [ Live Demo: Upload] ( https://demos.telerik.com/blazor-ui/upload/overview )
350-
0 commit comments