Base Path for File Manager

Hi, thanks for support. 
I have a folder with this situation:

├── User A ├── a ├── b ├── c ├── d ├── e ├── User B ├── f ├── g

I need to set the base path of the file manager component dynamically.

By setting the `path` property to 'User B' I can still access 'User A'

Image_7729_1694099630403

Can I fix this?


1 Reply

IL Indhumathy Loganathan Syncfusion Team September 8, 2023 02:32 PM UTC

Hi Filippo,


Greetings from Syncfusion support.


We understand that you want to dynamically set the root folder of File Manager component from the client end. To achieve this requirement, you need to set the default base path at server end and you can pass the folder name that you want to set as a root from client end on each request. You can send the root folder name in the below events.


File Operations

Events

GetImage

beforeImageLoad

Download

beforeDownload

Read, Delete, Upload, Rename, Copy

beforeSend


Read and Upload operations:

beforeSend(args: any) { 

    //Ajax beforeSend event 

    args.ajaxSettings.beforeSend = function (args) { 

      //Setting authorization header 

      args.httpRequest.setRequestHeader("Authorization", "user1\\user1-project1") 

    } 

  } 


GetImage operations:

beforeImageLoad: function (args) {

  // Add custom parameter in image URL

  args.imageUrl = args.imageUrl + "&user_name=" + "user1\\user1-project1";

},

Download operations:

beforeDownload: function (args) {

  // Assign your preferred root file name to the below variable and don't change other lines

  var value = "user1\\user1-project1";

  var includeCustomAttribute = args.data;

  includeCustomAttribute.user_name = value;

  args.data = includeCustomAttribute;

},


[HomeController.cs]

public class FileManagerDirectoryContentExtend : FileManagerDirectoryContent    

{    

    public string customvalue { get; set; }    

    public string user_name { get; set; }

}    

...

public object FileOperations([FromBody] FileManagerDirectoryContent args)  

        {       

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

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

            }  

[Route("Upload")]

public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string action, string data)

{

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

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

...

[Route("Download")]   

public IActionResult Download(string downloadInput)   

{   

            FileManagerDirectoryContentExtend args = JsonConvert.DeserializeObject<FileManagerDirectoryContentExtend>(downloadInput);   

            var root = args.customvalue;   

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

[Route("GetImage")]

public IActionResult GetImage(FileManagerDirectoryContentExtend args)

{

    var root = args. user_name;

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

    return this.operation.GetImage(args.Path, args.Id, false, null, null);

}


We have addressed similar requirement in the below forum.


https://www.syncfusion.com/forums/144270/how-to-implement-jwt-token-send-with-every-filemanager-request


https://www.syncfusion.com/forums/157578/customization-beyond-basic-implementations-source-customization


Check out the shared details and try at your end. If the provided details doesn’t work, share us the exact File Service provider used at your end. Please get back to us if you need any further assistance.


Regards,

Indhumathy L


Loader.
Up arrow icon