Skip to content

Commit b99ae59

Browse files
authored
Merge pull request #2902 from syncfusion-content/83631-dev
83631: Provide support for catch the returned response body in uploader component
2 parents d1e46a9 + 6a5b4d1 commit b99ae59

File tree

2 files changed

+134
-4
lines changed

2 files changed

+134
-4
lines changed

ej2-asp-core-mvc/uploader/EJ2_ASP.MVC/async.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,69 @@ public void Save()
167167
}
168168
```
169169

170+
### Server-side configure save action to returned response
171+
172+
The following example demonstrates how the server-side action for saving the file in server to returned response in JSON, String and file type data's.
173+
174+
```c#
175+
[AcceptVerbs("Post")]
176+
public ActionResult Save()
177+
{
178+
// for JSON Data
179+
try
180+
{
181+
// Process uploaded data
182+
var responseData = new
183+
{
184+
Success = true,
185+
Message = "Files uploaded successfully",
186+
// Additional data can be added here
187+
};
188+
189+
return Json(responseData);
190+
}
191+
catch (Exception e)
192+
{
193+
var errorResponse = new
194+
{
195+
Success = false,
196+
Message = "File upload failed: " + e.Message
197+
};
198+
199+
return Json(errorResponse);
200+
}
201+
202+
// for String Data
203+
try
204+
{
205+
// Process string data
206+
var data = "success";
207+
// Return the string data
208+
return Content(data);
209+
}
210+
catch (Exception)
211+
{
212+
var data = "failed";
213+
return Content(data);
214+
}
215+
216+
// for File Data
217+
try
218+
{
219+
// Example: Retrieve file path for stream.txt
220+
var filePath = "/stream.txt"; // Example file path
221+
222+
// Return the file
223+
return File(filePath, "text/plain");
224+
}
225+
catch (Exception e)
226+
{
227+
return Content("Failed to retrieve file response: " + e.Message, "text/plain");
228+
}
229+
}
230+
231+
```
232+
170233
## Remove action
171234

172235
The remove action is optional. Specify the URL to handle remove process from server.
@@ -302,9 +365,9 @@ By default, the uploader control process multiple files to upload simultaneously
302365

303366

304367

305-
## Preload files
368+
## Preloaded files
306369

307-
The uploader control allows you to preload the list of files that are uploaded in the server. The preloaded files are useful to view and remove the files from server that can be achieved by the [files](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Inputs.Uploader.html#Syncfusion_EJ2_Inputs_Uploader_Files) property. By default, the files are configured with uploaded successfully state on rendering file list. The following properties are mandatory to configure the preloaded files:
370+
The uploader control allows you to preloaded the list of files that are uploaded in the server. The preloaded files are useful to view and remove the files from server that can be achieved by the [files](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Inputs.Uploader.html#Syncfusion_EJ2_Inputs_Uploader_Files) property. By default, the files are configured with uploaded successfully state on rendering file list. The following properties are mandatory to configure the preloaded files:
308371

309372
* Name
310373
* Size

ej2-asp-core-mvc/uploader/EJ2_ASP.NETCORE/async.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,73 @@ public void Save(IList<IFormFile> chunkFile, IList<IFormFile> UploadFiles)
202202

203203
```
204204

205+
### Server-side configure save action to returned response
206+
207+
The following example demonstrates how the server-side action for saving the file in server to returned response in JSON, String and File type data's.
208+
209+
```c#
210+
[AcceptVerbs("Post")]
211+
public IActionResult Save()
212+
{
213+
// for JSON Data
214+
try
215+
{
216+
// Process uploaded data
217+
var responseData = new
218+
{
219+
Success = true,
220+
Message = "Files uploaded successfully",
221+
// Additional data can be added here
222+
};
223+
224+
return Json(responseData);
225+
}
226+
catch (Exception e)
227+
{
228+
var errorResponse = new
229+
{
230+
Success = false,
231+
Message = "File upload failed: " + e.Message
232+
};
233+
234+
return Json(errorResponse);
235+
}
236+
237+
// for String Data
238+
try
239+
{
240+
// Process string data
241+
var data = "success";
242+
// Return the string data
243+
return Content(data);
244+
}
245+
catch (Exception)
246+
{
247+
var data = "failed";
248+
return Content(data);
249+
}
250+
251+
// for File Data
252+
try
253+
{
254+
// Example: Retrieve file path for stream.txt
255+
var filePath = "stream.txt"; // Example file path
256+
257+
// Get full file path
258+
var fullPath = Path.GetFullPath(filePath);
259+
260+
// Return the file
261+
return PhysicalFile(fullPath, "text/plain");
262+
}
263+
catch (Exception e)
264+
{
265+
// Handle file retrieval failure
266+
return Content("Failed to retrieve file response: " + e.Message, "text/plain");
267+
}
268+
}
269+
270+
```
271+
205272
## Remove action
206273

207274
The remove action is optional. Specify the URL to handle remove process from server.
@@ -393,9 +460,9 @@ By default, the uploader control process multiple files to upload simultaneously
393460

394461

395462

396-
## Preload files
463+
## Preloaded files
397464

398-
The uploader control allows you to preload the list of files that are uploaded in the server. The preloaded files are useful to view and remove the files from server that can be achieved by the [files](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Inputs.Uploader.html#Syncfusion_EJ2_Inputs_Uploader_Files) property. By default, the files are configured with uploaded successfully state on rendering file list. The following properties are mandatory to configure the preloaded files:
465+
The uploader control allows you to preloaded the list of files that are uploaded in the server. The preloaded files are useful to view and remove the files from server that can be achieved by the [files](https://help.syncfusion.com/cr/aspnetcore-js2/Syncfusion.EJ2.Inputs.Uploader.html#Syncfusion_EJ2_Inputs_Uploader_Files) property. By default, the files are configured with uploaded successfully state on rendering file list. The following properties are mandatory to configure the preloaded files:
399466

400467
* Name
401468
* Size

0 commit comments

Comments
 (0)