<ejs-filemanager id='overview' (beforeSend)="beforeSend($event)" [ajaxSettings]='ajaxSettings' [view]='view'>
</ejs-filemanager>
//File Manager's beforeSend event
beforeSend(args: any){
//Ajax beforeSend event
args.ajaxSettings.beforeSend = function (args) {
//Setting authorization header
args.httpRequest.setRequestHeader("Authorization", "Bearer-1233")
}
} |
<ejs-filemanager #filemanager id='overview' [ajaxSettings]='ajaxSettings' (beforeSend)="beforeSend($event)" [view]='view' (toolbarClick)='toolbarClick($event)' (menuClick)='menuClick($event)'>
</ejs-filemanager>
beforeSend(args: any) {
//Ajax beforeSend event
args.ajaxSettings.beforeSend = function (args) {
//Setting authorization header
args.httpRequest.setRequestHeader("Authorization", "Bearer-1233")
}
}
|
[Controller]
Route("Download")]
public IActionResult Download(string downloadInput)
{
// To expose content disposition header at client side.
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
FileManagerDirectoryContent args = JsonConvert.DeserializeObject<FileManagerDirectoryContent>(downloadInput);
return operation.Download(args.Path, args.Names);
}
|
[TS]
public toolbarClick(args: any): void {
if (args.item.id === this.filemanagerObj.element.id + '_tb_download') {
//Preventing default download using toolbar
args.cancel = true;
this.customDownload([]);
}
}
public menuClick(args: any) {
if (args.item.id === this.filemanagerObj.element.id + '_cm_download') {
//Preventing default download using context menu
args.cancel = true;
this.customDownload(args.fileDetails);
}
}
public customDownload(files) {
var flag = (this.filemanagerObj.selectedItems.length !== 0);
if ((files.length !== 0) || flag) {
//Creating data for the controller
.....
.....
let fdata: FormData = new FormData();
fdata.append('downloadInput', JSON.stringify(data));
//Custom Header Added to XHR
xhr.setRequestHeader('Custom-Header', 'Syncfusion');
xhr.send(fdata);
}
}
|
beforeSend(args: any) {
var data = JSON.parse(args.ajaxSettings.data);
// Add custom parameter column
data["column"] = "value";
// Add custom parameter in ajax settings
args.ajaxSettings.data = JSON.stringify(data);
//Ajax beforeSend event
args.ajaxSettings.beforeSend = function (args) {
//Setting authorization header
args.httpRequest.setRequestHeader("Authorization", "Bearer-1233")
}
}
|
public class FileManagerDirectoryContent1
{
public string Action { get; set; }
public string Path { get; set; }
public FileManagerDirectoryContent TargetData { get; set; }
public AccessPermission Permission { get; set; }
public string column { get; set; }
} |
beforeSend(args: any) { var data = JSON.parse(args.ajaxSettings.data); // Add custom parameter column data["column"] = "value"; // Add custom parameter in ajax settings args.ajaxSettings.data = JSON.stringify(data); //Ajax beforeSend event args.ajaxSettings.beforeSend = function (args) { //Setting authorization header args.httpRequest.setRequestHeader("Authorization", "Bearer-1233") } } |
beforeSend(args: any) {
//Ajax beforeSend event
args.ajaxSettings.beforeSend = function (args) {
//Setting authorization header
// It is not a static token.
args.httpRequest.setRequestHeader("Authorization", "Bearer-1233")
}
}
|
var data = {
'action':
'path':
'names':
'data':
}; |
<ejs-filemanager
id="overview"
[ajaxSettings]="ajaxSettings"
(beforeImageLoad)="beforeImageLoad($event)"
[view]="view"
>
</ejs-filemanager>
beforeImageLoad(args) {
// Add custom parameter in image URL
args.imageUrl = args.imageUrl + "&custom_attribute=" + "Syncfusion";
} |
public class FileManagerDirectoryContent1
{
public string Name { get; set; }
public string custom_attribute { get; set; }
public string[] Names { get; set; }
}
[Route("GetImage")]
public IActionResult GetImage(FileManagerDirectoryContent1 args)
{
return this.operation.GetImage(args.Path, args.Id,false,null, null);
} |
Hi Luke Mitchell,Based on the current implementation of FileManager component, we have used form submit for download operations of FileManager component and not a ajax request. So, we can’t add the JWT token with this request. However, you can add the custom data to the download operations using beforeDownload event.Please, refer the below forum link for beforeDownload operations.However, we have used Query parameter for GetImage operations of FileManager component. Other than the two operations ( Download, GetImage), you can send the JWT token using beforeSend event of FileManager component.Please let us know, if you need any further assistance.Regards,Sowmiya.P
We have implemented customdownload() function in react and now we are able to pass the keycloak username and token to download api in file manager. But the downloaded file is of 'file' type instead of original file type. For eg: if we download word document, downloaded file is of 'file' type instead of '.doc' and we have to open it using ms word only. Also, the name of the file is also changed.
Hi Jyoti,
We have prepared a simple sample of the React FileManager component with a custom download operation, and the sample works fine with the proper downloaded file. We suspect that the issue occurs due to missing Content-Disposition code details on your controller side.
To overcome the issue, we suggest you include the below code changes in your controller Download method. We have attached the prepared service provider with a sample for your reference.
Refer to the below code snippet.
[FileManagerController.cs]
[Route("Download")] public IActionResult Download(string downloadInput) { var headerValue = Request.Headers["Custom-Header"].ToString(); Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition"); FileManagerDirectoryContent args = JsonConvert.DeserializeObject<FileManagerDirectoryContent>(downloadInput); return operation.Download(args.Path, args.Names, args.Data); }
|
Sample: https://stackblitz.com/edit/react-vuwczm?file=index.js
Service provider: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-aspcore-file-provider1999555932.zip
Please check the attached sample and get back to us if you need any further assistance.
Regards,
Sivakumar S
Here is an entirely client-side solution that is working for me, which I prefer strongly over the solutions discussed above. In my case, I couldn't adjust the auth behavior of the server-side code, because we integrated the FileManager service's controllers into our overall app and I didn't want to start making one-off tweaks to accommodate this SyncFusion quirk.
So here you go...
In my Angular app I have a service providing custom operations to the FileManager back-end. This service is also the source-of-truth that provides the AjaxSettings properies everywhere throughout the app. You could structure it differently, but whatever the case, the following code needs to run before the FileManager component starts firing HTTP requests to the server.