I am using the syncfusion FileManager with azure blob storage. I need to cancel the call and pass in my own response to FileManager

How can I pass custom data from the server to the client while canceling the call in the "beforeSend" event, and instead of using the default HTTP call, using my own HTTP call to obtain the response, while still being able to provide that response to the FileManager?


3 Replies

SA SureshRajan Alagarsamy Syncfusion Team June 9, 2023 04:12 PM UTC

Hi Alex,


We have reviewed your query and understand that you are seeking guidance on how to send custom data in the existing File Manager response from the server end to the client end in the File Manager component with the Azure File Provider. We would like to inform you that this requirement can be achieved on the server side. Refer to the below code snippet for further reference.


[AzureProviderController.cs]

 

namespace EJ2AzureASPCoreFileProvider.Controllers

{

    public class FileResponse

    {

        public FileManagerDirectoryContent1 CWD { get; set; }

 

        public IEnumerable<FileManagerDirectoryContent1> Files { get; set; }

 

        public ErrorDetails Error { get; set; }

 

        public FileDetails Details { get; set; }

    }

 

    public class FileManagerDirectoryContent1 : FileManagerDirectoryContent

    {

        public string custom_data { get; set; }

    }

 

    ….

    public object getFiles(FileManagerDirectoryContent1 args)

     {

            FileResponse readResponse = new FileResponse();

            try

            {

                var value = this.operation.GetFiles(args.Path, args.ShowHiddenItems, args.Data);

                FileManagerDirectoryContent1 cwd = new FileManagerDirectoryContent1();

                readResponse.CWD = JsonConvert.DeserializeObject<FileManagerDirectoryContent1>(JsonConvert.SerializeObject(value.CWD));

                readResponse.CWD.custom_data = "dummyText";

                readResponse.Files = JsonConvert.DeserializeObject<IEnumerable<FileManagerDirectoryContent1>>(JsonConvert.SerializeObject(value.Files));

                //Add the additional parameter for each files in File Manager component.

                foreach (FileManagerDirectoryContent1 file in readResponse.Files)

                {

                        //Add the CustomValue as additional parameter.

                        file.custom_data = "dummyText";

                }

                readResponse.Details = value.Details;

                readResponse.Error = value.Error;

                return readResponse;

            }

            catch

            {

                ErrorDetails er = new ErrorDetails();

 

            }

            return this.ToCamelCase(this.operation.GetFiles(args.Path, args.ShowHiddenItems, args.Data));

       }

 

        [Route("AzureFileOperations")]

        public object AzureFileOperations([FromBody] FileManagerDirectoryContent1 args)

        {

            ….

 

            switch (args.Action)

            {

                case "read":

                    // Reads the file(s) or folder(s) from the given path.

                    return this.getFiles(args);

 

              ….

 

            }

            return null;

        }


In the above code snippet, we have included the “getFiles” method and triggered it in the "read" action. In this method, we added the “custom_data” as an additional value in the existing response for Root folder and for all the files and folders within it. In this way you can add additional data to the existing File Manager response on the server side.


We have also attached a screenshot for your reference, which shows the response, where you can see the “custom_data” value for all files and folders.


Screenshot :



We have attached the sample for your reference.


Sample : https://stackblitz.com/edit/react-p7fg5g?file=index.js


File Provider : Attached as zip folder


Check out the shared details and get back to us if you need any further assistance.


Regards,
Suresh.


Attachment: AzureFileProvider_d811ff20.zip


AM Alex Mercer June 12, 2023 08:37 PM UTC

Hi Suresh,

Thank you for that response. To continue on with my question, I have the option to cancel the original http call with args.cancel = true; I then want to use my own call through axios, how can I pass the response received through axios into the file manager? And is there a way to change how the file manager, on the frontend, interacts with the new custom data?


Thanks



SA SureshRajan Alagarsamy Syncfusion Team June 13, 2023 11:59 AM UTC

Hi Alex,


Query : How can I pass the response received through axios into the file manager?


In the File Manager component, we have handled file operations by fetching the response from the server. You can find the default response format for file operations at the following link. With this default response you can able to properly connect with our File Manager component.


Documentation : https://ej2.syncfusion.com/javascript/documentation/file-manager/file-operations/#file-operation-request-and-response-parameters


Additionally, we have listed the response parameters for some of the basic operations in the table below.


S.No

File Operation

Example Response Parameters

1

Read

{

  cwd:

  {

      name:"Download",

      size:0,

      dateModified:"2019-02-28T03:48:19.8319708+00:00",

      dateCreated:"2019-02-27T17:36:15.812193+00:00",

      hasChild:false,

      isFile:false,

      type:"",

      filterPath:\\Download\\

  },

  files:[

      {

          name:"Sample Work Sheet.xlsx",

          size:6172,

          dateModified:"2019-02-27T17:23:50.9651206+00:00",

          dateCreated:"2019-02-27T17:36:15.8151955+00:00",

          hasChild:false,

          isFile:true,

          type:".xlsx",

          filterPath:\\Download\\

      }

  ],

  error:null,

  details:null

}

2

Upload

The upload response is an empty string.

3

Download

Downloads the requested items from the file server in response.

4

GetImage

Return the image as a file stream in response.

5

Create

{

  cwd: null,

  files: [

      {

          dateCreated: "2019-03-15T10:25:05.3596171+00:00",

          dateModified: "2019-03-15T10:25:05.3596171+00:00",

          filterPath: null,

          hasChild: false,

          isFile: false,

          name: "New",

          size: 0,

          type: ""

      }

  ],

  details: null,

  error: null

}

6

Rename

{

  cwd:null,

  files:[

      {

          name:"seaview.jpg",

          size:95866,

          dateModified:"2019-03-20T08:45:56+00:00",

          dateCreated:"2019-03-20T05:22:34.6214847+00:00",

          hasChild:false,

          isFile:true,

          type:".jpg",

          filterPath:\\Pictures\\Nature\\seaview.jpg

      }

  ],

  error:null,

  details:null

}

 

7

Move

{

  cwd:null,

  files:[

      {

          path:null,

          action:null,

          newName:null,

          names:null,

          name:"justin biber.mp4",

          size:0,

          previousName:"justin biber.mp4",

          dateModified:"2019-06-21T06:58:32+00:00",

          dateCreated:"2019-06-24T04:26:49.2690476+00:00",

          hasChild:false,

          isFile:true,

          type:".mp4",

          id:null,

          filterPath:\\Videos\\

      }

  ],

  error:null,

  details:null

}

 

8

Copy

{

  cwd:null,

  files:[

      {

          path:null,

          action:null,

          newName:null,

          names:null,

          name:"justin.mp4",

          size:0,

          previousName:"album.mp4",

          dateModified:"2019-06-21T06:58:32+00:00",

          dateCreated:"2019-06-24T04:22:14.6245618+00:00",

          hasChild:false,

          isFile:true,

          type:".mp4",

          id:null,

          filterPath:"\\"

      }

  ],

  error:null,

  details:null

}

 

9

Delete

{

  cwd: null,

  details: null,

  error: null,

  files: [

      {

          dateCreated: "2019-03-15T10:13:30.346309+00:00",

          dateModified: "2019-03-15T10:13:30.346309+00:00",

          filterPath: "\Hello\folder",

          hasChild: true,

          isFile: false,

          name: "folder",

          size: 0,

          type: ""

      }

  ]

}

 

10

Details

{

  cwd:null,

  files:null,

  error:null,

  details:

  {

      name:"All Files",

      location:\\Files\\FileContents\\All Files,

      isFile:false,

      size:"679.8 KB",

      created:"3/8/2019 10:18:37 AM",

      modified:"3/8/2019 10:18:39 AM",

      multipleFiles:false

  }

}

 


Check out the shared details and get back to us if you need any further assistance.


Regards,
Suresh.


Loader.
Up arrow icon