How to pass folder paths in Angular 6 Get API Method?












0














In my angular application, I have to pass an Id and a folder path as a parameter in Angular 6.



Please see the below code snippet
in typescript



let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.http.get<ItemDetails>(this.appService.baseUrl + 'api/File/' + id + "/" + subDirectory)


Here the problem is: the API call becomes



this.http.get(this.appService.baseUrl + 'api/File/' + id + "/" + "folder1/folder2/folder3")



if we have only "folder1" as subdirectory then no issues.
"/folder2/folder3" makes the issue



in Controller



[HttpGet("{id:int}/{subDirectotry?}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
}


Please, anyone, help me to achieve the same.










share|improve this question




















  • 1




    And what is the problem?
    – Antoniossss
    2 days ago










  • updated question
    – Krishnan
    2 days ago










  • Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
    – Antoniossss
    2 days ago
















0














In my angular application, I have to pass an Id and a folder path as a parameter in Angular 6.



Please see the below code snippet
in typescript



let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.http.get<ItemDetails>(this.appService.baseUrl + 'api/File/' + id + "/" + subDirectory)


Here the problem is: the API call becomes



this.http.get(this.appService.baseUrl + 'api/File/' + id + "/" + "folder1/folder2/folder3")



if we have only "folder1" as subdirectory then no issues.
"/folder2/folder3" makes the issue



in Controller



[HttpGet("{id:int}/{subDirectotry?}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
}


Please, anyone, help me to achieve the same.










share|improve this question




















  • 1




    And what is the problem?
    – Antoniossss
    2 days ago










  • updated question
    – Krishnan
    2 days ago










  • Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
    – Antoniossss
    2 days ago














0












0








0







In my angular application, I have to pass an Id and a folder path as a parameter in Angular 6.



Please see the below code snippet
in typescript



let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.http.get<ItemDetails>(this.appService.baseUrl + 'api/File/' + id + "/" + subDirectory)


Here the problem is: the API call becomes



this.http.get(this.appService.baseUrl + 'api/File/' + id + "/" + "folder1/folder2/folder3")



if we have only "folder1" as subdirectory then no issues.
"/folder2/folder3" makes the issue



in Controller



[HttpGet("{id:int}/{subDirectotry?}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
}


Please, anyone, help me to achieve the same.










share|improve this question















In my angular application, I have to pass an Id and a folder path as a parameter in Angular 6.



Please see the below code snippet
in typescript



let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.http.get<ItemDetails>(this.appService.baseUrl + 'api/File/' + id + "/" + subDirectory)


Here the problem is: the API call becomes



this.http.get(this.appService.baseUrl + 'api/File/' + id + "/" + "folder1/folder2/folder3")



if we have only "folder1" as subdirectory then no issues.
"/folder2/folder3" makes the issue



in Controller



[HttpGet("{id:int}/{subDirectotry?}")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string subDirectotry)
{
}


Please, anyone, help me to achieve the same.







angular typescript asp.net-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked 2 days ago









Krishnan

507621




507621








  • 1




    And what is the problem?
    – Antoniossss
    2 days ago










  • updated question
    – Krishnan
    2 days ago










  • Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
    – Antoniossss
    2 days ago














  • 1




    And what is the problem?
    – Antoniossss
    2 days ago










  • updated question
    – Krishnan
    2 days ago










  • Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
    – Antoniossss
    2 days ago








1




1




And what is the problem?
– Antoniossss
2 days ago




And what is the problem?
– Antoniossss
2 days ago












updated question
– Krishnan
2 days ago




updated question
– Krishnan
2 days ago












Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
– Antoniossss
2 days ago




Typescript part is irrelevant here. paste full url you are trying to access and gives you 404
– Antoniossss
2 days ago












3 Answers
3






active

oldest

votes


















0














in simple words, define a function to call api in your service



getItemsDetails (id: number, subDirectory: string) {
return this.http.get<ItemDetails>(`${this.appService.baseUrl}api/File/${id}/${ subDirectory}`);
}


to call in componnet;



let subDirectory: string = "folder1/folder2/folder3";
let id: number = 6 ;
this.serviceName.getItemsDetails(id, subDirectory).subscribe(() => {
// -> do what ever you want do with response.
})





share|improve this answer





























    0














    Most probably you're getting 404 errors , try to encode the subDirectory using encodeURIComponent , then try to unescape once you receive the request.






    share|improve this answer





























      0














      You could try catch-all route parameters with {*} like below:



      [HttpGet("{id:int}/{*subDirectotry}")]
      [ResponseCache(NoStore = true)]
      public async Task<IActionResult> Get(int id, string subDirectotry)
      {
      return Ok();
      }





      share|improve this answer





















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945492%2fhow-to-pass-folder-paths-in-angular-6-get-api-method%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        in simple words, define a function to call api in your service



        getItemsDetails (id: number, subDirectory: string) {
        return this.http.get<ItemDetails>(`${this.appService.baseUrl}api/File/${id}/${ subDirectory}`);
        }


        to call in componnet;



        let subDirectory: string = "folder1/folder2/folder3";
        let id: number = 6 ;
        this.serviceName.getItemsDetails(id, subDirectory).subscribe(() => {
        // -> do what ever you want do with response.
        })





        share|improve this answer


























          0














          in simple words, define a function to call api in your service



          getItemsDetails (id: number, subDirectory: string) {
          return this.http.get<ItemDetails>(`${this.appService.baseUrl}api/File/${id}/${ subDirectory}`);
          }


          to call in componnet;



          let subDirectory: string = "folder1/folder2/folder3";
          let id: number = 6 ;
          this.serviceName.getItemsDetails(id, subDirectory).subscribe(() => {
          // -> do what ever you want do with response.
          })





          share|improve this answer
























            0












            0








            0






            in simple words, define a function to call api in your service



            getItemsDetails (id: number, subDirectory: string) {
            return this.http.get<ItemDetails>(`${this.appService.baseUrl}api/File/${id}/${ subDirectory}`);
            }


            to call in componnet;



            let subDirectory: string = "folder1/folder2/folder3";
            let id: number = 6 ;
            this.serviceName.getItemsDetails(id, subDirectory).subscribe(() => {
            // -> do what ever you want do with response.
            })





            share|improve this answer












            in simple words, define a function to call api in your service



            getItemsDetails (id: number, subDirectory: string) {
            return this.http.get<ItemDetails>(`${this.appService.baseUrl}api/File/${id}/${ subDirectory}`);
            }


            to call in componnet;



            let subDirectory: string = "folder1/folder2/folder3";
            let id: number = 6 ;
            this.serviceName.getItemsDetails(id, subDirectory).subscribe(() => {
            // -> do what ever you want do with response.
            })






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 days ago









            rijin

            934514




            934514

























                0














                Most probably you're getting 404 errors , try to encode the subDirectory using encodeURIComponent , then try to unescape once you receive the request.






                share|improve this answer


























                  0














                  Most probably you're getting 404 errors , try to encode the subDirectory using encodeURIComponent , then try to unescape once you receive the request.






                  share|improve this answer
























                    0












                    0








                    0






                    Most probably you're getting 404 errors , try to encode the subDirectory using encodeURIComponent , then try to unescape once you receive the request.






                    share|improve this answer












                    Most probably you're getting 404 errors , try to encode the subDirectory using encodeURIComponent , then try to unescape once you receive the request.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 2 days ago









                    Haidar Zeineddine

                    8325




                    8325























                        0














                        You could try catch-all route parameters with {*} like below:



                        [HttpGet("{id:int}/{*subDirectotry}")]
                        [ResponseCache(NoStore = true)]
                        public async Task<IActionResult> Get(int id, string subDirectotry)
                        {
                        return Ok();
                        }





                        share|improve this answer


























                          0














                          You could try catch-all route parameters with {*} like below:



                          [HttpGet("{id:int}/{*subDirectotry}")]
                          [ResponseCache(NoStore = true)]
                          public async Task<IActionResult> Get(int id, string subDirectotry)
                          {
                          return Ok();
                          }





                          share|improve this answer
























                            0












                            0








                            0






                            You could try catch-all route parameters with {*} like below:



                            [HttpGet("{id:int}/{*subDirectotry}")]
                            [ResponseCache(NoStore = true)]
                            public async Task<IActionResult> Get(int id, string subDirectotry)
                            {
                            return Ok();
                            }





                            share|improve this answer












                            You could try catch-all route parameters with {*} like below:



                            [HttpGet("{id:int}/{*subDirectotry}")]
                            [ResponseCache(NoStore = true)]
                            public async Task<IActionResult> Get(int id, string subDirectotry)
                            {
                            return Ok();
                            }






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 2 days ago









                            Tao Zhou

                            4,87031128




                            4,87031128






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945492%2fhow-to-pass-folder-paths-in-angular-6-get-api-method%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Mossoró

                                Error while reading .h5 file using the rhdf5 package in R

                                Pushsharp Apns notification error: 'InvalidToken'