Skip to content

Updated UG document for new feature in get image #4296

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

Open
wants to merge 1 commit into
base: hotfix/hotfix-v29.2.4
Choose a base branch
from
Open
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
45 changes: 22 additions & 23 deletions ej2-asp-core-mvc/file-manager/how-to/pass-custom-value-to-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public object Download([FromBody] FileManagerDirectoryContent args)

## 4. For GetImage Operation

For the **GetImage** operation, use the **beforeImageLoad** event to pass custom value. Since the **GetImage** operation doesn't support custom headers in HTTP requests, pass the custom values along with **imageUrl** using query parameters instead.
For the **GetImage** operation, use the beforeImageLoad event. Inside this event, set useImageAsUrl to false to instruct the FileManager not to load the image directly via its URL but instead to use a fetch request. Here, attach the **Authorization** header with the value **User1** within the beforeSend event of the ajaxSettings.

{% if page.publishingplatform == "aspnet-core" %}
```ts
Expand All @@ -199,8 +199,14 @@ For the **GetImage** operation, use the **beforeImageLoad** event to pass custom

<script>
function beforeImageLoad(args) {
// Add custom parameter in image URL
args.imageUrl = args.imageUrl + "&Authorization=" + "User1";
args.useImageAsUrl = false;
// Check if ajaxSettings are present in the arguments
if (args.ajaxSettings) {
(args.ajaxSettings).beforeSend = function (args) {
// Append Authorization header with value 'User1' to fetchRequest headers
args.fetchRequest.headers.append('Authorization', 'User1');
};
}
}
</script>

Expand All @@ -222,35 +228,28 @@ For the **GetImage** operation, use the **beforeImageLoad** event to pass custom

<script>
function beforeImageLoad(args) {
// Add custom parameter in image URL
args.imageUrl = args.imageUrl + "&Authorization=" + "User1";
args.useImageAsUrl = false;
// Check if ajaxSettings are present in the arguments
if (args.ajaxSettings) {
(args.ajaxSettings).beforeSend = function (args) {
// Append Authorization header with value 'User1' to fetchRequest headers
args.fetchRequest.headers.append('Authorization', 'User1');
};
}
}
</script>
```
{% endif %}

In server-side, you can able to get the custom query parameter value using **Authorization** in `GetImage` method. To get the custom query parameter value, extend the `FileManagerDirectoryContent` class and add the custom property **Authorization**.
In server-side, `GetImage` method access the **Authorization** header from the incoming HTTP request and perform the necessary operations.

```typescript

public class FileManagerAccessController : Controller
[Route("GetImage")]
public object GetImage([FromBody] FileManagerDirectoryContent args)
{
...
public class FileManagerDirectoryContent1 : FileManagerDirectoryContent
{
public string Authorization { get; set; }
}
...

// gets the image(s) from the given path
[Route("GetImage")]
public IActionResult GetImage(FileManagerDirectoryContent1 args)
{
var header = args.Authorization;
return this.operation.GetImage(args.Path, args.Id, false, null, null);
}

...
var header = HttpContext.Request.Headers["Authorization"];
return this.operation.GetImage(args.Path, args.Id, false, null, null);
}


Expand Down