Skip to content

83631: Provide support for catch the returned response body in uploader component #2902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions ej2-asp-core-mvc/uploader/EJ2_ASP.MVC/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,69 @@ public void Save()
}
```

### Server-side configure save action to returned response

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.

```c#
[AcceptVerbs("Post")]
public ActionResult Save()
{
// for JSON Data
try
{
// Process uploaded data
var responseData = new
{
Success = true,
Message = "Files uploaded successfully",
// Additional data can be added here
};

return Json(responseData);
}
catch (Exception e)
{
var errorResponse = new
{
Success = false,
Message = "File upload failed: " + e.Message
};

return Json(errorResponse);
}

// for String Data
try
{
// Process string data
var data = "success";
// Return the string data
return Content(data);
}
catch (Exception)
{
var data = "failed";
return Content(data);
}

// for File Data
try
{
// Example: Retrieve file path for stream.txt
var filePath = "/stream.txt"; // Example file path

// Return the file
return File(filePath, "text/plain");
}
catch (Exception e)
{
return Content("Failed to retrieve file response: " + e.Message, "text/plain");
}
}

```

## Remove action

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



## Preload files
## Preloaded files

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:
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:

* Name
* Size
Expand Down
71 changes: 69 additions & 2 deletions ej2-asp-core-mvc/uploader/EJ2_ASP.NETCORE/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,73 @@ public void Save(IList<IFormFile> chunkFile, IList<IFormFile> UploadFiles)

```

### Server-side configure save action to returned response

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.

```c#
[AcceptVerbs("Post")]
public IActionResult Save()
{
// for JSON Data
try
{
// Process uploaded data
var responseData = new
{
Success = true,
Message = "Files uploaded successfully",
// Additional data can be added here
};

return Json(responseData);
}
catch (Exception e)
{
var errorResponse = new
{
Success = false,
Message = "File upload failed: " + e.Message
};

return Json(errorResponse);
}

// for String Data
try
{
// Process string data
var data = "success";
// Return the string data
return Content(data);
}
catch (Exception)
{
var data = "failed";
return Content(data);
}

// for File Data
try
{
// Example: Retrieve file path for stream.txt
var filePath = "stream.txt"; // Example file path

// Get full file path
var fullPath = Path.GetFullPath(filePath);

// Return the file
return PhysicalFile(fullPath, "text/plain");
}
catch (Exception e)
{
// Handle file retrieval failure
return Content("Failed to retrieve file response: " + e.Message, "text/plain");
}
}

```

## Remove action

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



## Preload files
## Preloaded files

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:
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:

* Name
* Size
Expand Down