Skip to content

Commit 604b000

Browse files
Merge pull request #4363 from syncfusion-content/965445-getimag
Updated UG document for new feature in get image
2 parents f9dcf49 + 7dfe6d7 commit 604b000

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

ej2-asp-core-mvc/file-manager/how-to/pass-custom-value-to-server.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public object Download([FromBody] FileManagerDirectoryContent args)
181181

182182
## 4. For GetImage Operation
183183

184-
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.
184+
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.
185185

186186
{% if page.publishingplatform == "aspnet-core" %}
187187
```ts
@@ -200,7 +200,14 @@ For the **GetImage** operation, use the **beforeImageLoad** event to pass custom
200200
<script>
201201
function beforeImageLoad(args) {
202202
// Add custom parameter in image URL
203-
args.imageUrl = args.imageUrl + "&Authorization=" + "User1";
203+
args.useImageAsUrl = false;
204+
// Check if ajaxSettings are present in the arguments
205+
if (args.ajaxSettings) {
206+
(args.ajaxSettings).beforeSend = function (args) {
207+
// Append Authorization header with value 'User1' to fetchRequest headers
208+
args.fetchRequest.headers.append('Authorization', 'User1');
209+
};
210+
}
204211
}
205212
</script>
206213

@@ -222,38 +229,31 @@ For the **GetImage** operation, use the **beforeImageLoad** event to pass custom
222229

223230
<script>
224231
function beforeImageLoad(args) {
225-
// Add custom parameter in image URL
226-
args.imageUrl = args.imageUrl + "&Authorization=" + "User1";
232+
// Add custom parameter in image URL
233+
args.useImageAsUrl = false;
234+
// Check if ajaxSettings are present in the arguments
235+
if (args.ajaxSettings) {
236+
(args.ajaxSettings).beforeSend = function (args) {
237+
// Append Authorization header with value 'User1' to fetchRequest headers
238+
args.fetchRequest.headers.append('Authorization', 'User1');
239+
};
240+
}
227241
}
228242
</script>
229243
```
230244
{% endif %}
231245

232-
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**.
233-
246+
In server-side, `GetImage` method access the **Authorization** header from the incoming HTTP request and perform the necessary operations.
234247
```typescript
235248

236-
public class FileManagerAccessController : Controller
249+
// gets the image(s) from the given path
250+
[Route("GetImage")]
251+
public object GetImage([FromBody] FileManagerDirectoryContent args)
237252
{
238-
...
239-
public class FileManagerDirectoryContent1 : FileManagerDirectoryContent
240-
{
241-
public string Authorization { get; set; }
242-
}
243-
...
244-
245-
// gets the image(s) from the given path
246-
[Route("GetImage")]
247-
public IActionResult GetImage(FileManagerDirectoryContent1 args)
248-
{
249-
var header = args.Authorization;
250-
return this.operation.GetImage(args.Path, args.Id, false, null, null);
251-
}
252-
253-
...
253+
var header = args.Authorization;
254+
return this.operation.GetImage(args.Path, args.Id, false, null, null);
254255
}
255256

256-
257257
```
258258

259259
> **Note:** View the complete [Github sample](https://github.com/SyncfusionExamples/How-to-pass-custom-values-from-client-to-server-in-filemanager) which includes all the above event along with service code for passing custom values to server.

0 commit comments

Comments
 (0)