Passing Root Folder as Ajax Headers

Hi,

I have FileManger based on Physical File. Everything working fine. I need add features that enabled the setup for the root folder is passed through Ajax Headers through ajaxSettings:

    public class FileManagerController : Controller
    {
        public PhysicalFileProvider operation;
        public string basePath;
        string root = "wwwroot\\Files";


            var hostUrl = '/';
            var fileObject = new ej.filemanager.FileManager({
                height: getDashminFileManagerHeight(),
                ajaxSettings: {
                    url: hostUrl + 'api/FileManager/FileOperations',
                    getImageUrl: hostUrl + 'api/FileManager/GetImage',
                    uploadUrl: hostUrl + 'api/FileManager/Upload',
                    downloadUrl: hostUrl + 'api/FileManager/Download'
                },

Thank you,

Ismail


2 Replies 1 reply marked as answer

JA Jafar Ali Shahulhameed Syncfusion Team April 15, 2024 05:02 PM UTC

Hi Ismail,


Based on the shared details we can understand that you are trying to utilize Syncfusion File Manager component. We would like to inform you that you can update the root folder of the File Manager component by making use of the authentication headers in the File Manager beforeSend event. Kindly refer the code changes below,


[index.js]

 

function onBeforeSend(args) {

    args.ajaxSettings.beforeSend = function($args) {

        $args.httpRequest.setRequestHeader('Authorization', 'Music');

    };

}



[FileManagerController.cs]

 

[Route("FileOperations")]

public object FileOperations([FromBody] FileManagerDirectoryContent args)

{

    var root = HttpContext.Request.Headers["Authorization"];

    this.operation.RootFolder(this.basePath + "\\" + this.root + "\\" + root);

    …

    …

}


We have also attached the sample for your reference,


Sample: https://stackblitz.com/edit/q8cezp-zn9sux?file=index.js,index.html


Service Provider: https://github.com/SyncfusionExamples/ej2-aspcore-file-provider


It is important to note that you have to clone and run the service sample to work on the shared File Manager sample. After running the project, it will be hosted in http://localhost:{port} and just mapping the ajaxSettings property of the FileManager component to the appropriate controller methods allows to manage the files in the provider. We have made this necessary changes in the attached sample itself.


Kindly try out the shared details and get back to us if you need further assistance.


Regards,

Jafar


Marked as answer

IH ISMAIL HAMZAH April 15, 2024 10:41 PM UTC

Hi Jafar,


Awesome! Your solution working perfectly, that's what's I need.

Thank you for the help!


Best regards,

Ismail H


Loader.
Up arrow icon