App Connect

 View Only
  • 1.  How can we upload a PDF file in IBM API Connect using rest API?

    Posted Tue February 14, 2023 11:18 PM

    We are trying upload a pdf file in respective destination through IBM API Connect.

    However we found the pdf file is uploaded without the name of the file.

    we have used

    method = Put

    Protocol = HTTP / HTTPS

    Body - Multi-Part

    Type - File

    In invoke we have given the target path as https://<host>:<port>/nlpmDev/Transport/$(request.body.pdfFile)

    So requesting to help on this.



    ------------------------------
    Nrusingha Sahoo
    ------------------------------


  • 2.  RE: How can we upload a PDF file in IBM API Connect using rest API?

    IBM Champion
    Posted Wed February 15, 2023 02:24 AM
    Edited by Matthias Blomme Wed February 15, 2023 02:25 AM

    Hi Nrusingha

    To start with, creating a new file should be a post request (according to standard REST, put = update, post = create new)

    Normal message flow with http input

    You can add the name of the pdf as a query parameter

    If I do a put to http://localhost:7800/pdf/upload?psab.pdf with the pdf contents in the body, I get the following in ace (simple message flow with http input):

    Rest API 

    Or if you create a rest api, you can add the name parameter in the url you are going to call.

    You can define that last part of the path as a variable that will capture that param in your flow.

    Rest api example:

    openapi3.0.0
    info:
      titlePDF
      version1.0.0
      descriptionPDF
    servers:
      - url/pdf/v1
    paths:
      /upload/{pdfName}:
        post:
          responses:
            '200':
              descriptionsuccess
          requestBody:
            content:
              application/octet-stream:
                schema:
                  typestring
                  formatbinary
        parameters:
          - namepdfName
            inpath
            schema:
              typestring
            requiredtrue
            descriptionthe name of the pdf
    Call url example:
    http://localhost:7800/pdf/v1/upload/name.pdf
    In the toolkit debug:
    From there you can do with the name whatever you want.


    Hope this helps a bit.
    ------------------------------
    Regards
    Matthias Blomme
    ------------------------------



  • 3.  RE: How can we upload a PDF file in IBM API Connect using rest API?

    Posted Wed February 15, 2023 03:47 AM

    Hi Matthias Blomme,

    Thanks for your quick response.

    I want to upload the file dynamically as it comes as a request from consumer.
    I need to set the file name and path parameter and query string dynamically.

    For this I hope I need to use gateway script. Please confirm the same.

    In rest API,

    I could not understand the points highlighted as green color so can you please elaborate on these as I am new to APP Connect

    paths:
      /upload/{pdfName}:
        post:
          responses:
            '200':
              descriptionsuccess
          requestBody:
            content:
              application/octet-stream:
                schema:
                  typestring
                  formatbinary
        parameters:
          - namepdfName
            inpath
            schema:
              typestring
            requiredtrue
            descriptionthe name of the pdf


    ------------------------------
    Nrusingha Sahoo
    ------------------------------



  • 4.  RE: How can we upload a PDF file in IBM API Connect using rest API?

    IBM Champion
    Posted Wed February 15, 2023 06:10 AM
    Edited by Matthias Blomme Tue February 21, 2023 05:40 AM

    Hi Nrusingha 

    How does the flow work?

    You have created a RESTAPI that you host on ACE and the consumer uploads a pdf there? 

    If you upload a pdf, you have access to the file because you need to read it, so adding the filename in the url path should be easy.

    For your questions:

    • application/octet-stream is just to upload the pdf in its entirety.
    • the name of the parem "pdfName" is the same as the variable in the second line: {pdfName}
    • description is just a description of the parameter, just to indicate what the parameter is.

    I've attached an example REST Api, if you upload a file (with postman for instance) it will take it and write it to file with the name in the url (it will also return the pdf back to your calling application). 

    I call the application by doing a post call to http://localhost:7800/pdf/v1/upload/name.pdf (of course port can be different for you). I've uploaded the postman collection as well (just one call).

    Hope that helps



    ------------------------------
    Regards
    Matthias Blomme
    ------------------------------

    Attachment(s)



  • 5.  RE: How can we upload a PDF file in IBM API Connect using rest API?

    Posted Wed February 15, 2023 06:28 AM

    Hi Matthias Blomme,

    Thanks for your message.

    Our concern is consumer does not want to send the file name as a separate parameter. They simply browsing the file and attach, then send to us.

    Even they are sending the files as txt, doc/docx etc...

    So we are struggling to get the file name dynamically from Multi-Part.

    It would be helpful if we can have solution for this.

    We are happy to use the gateway script.

    Thanks in advance.

    Thanks



    ------------------------------
    Nrusingha Sahoo
    ------------------------------



  • 6.  RE: How can we upload a PDF file in IBM API Connect using rest API?

    IBM Champion
    Posted Wed February 15, 2023 11:04 AM

    Hi Nrusingha

    I  noticed you also posted your question in the API connect community, so it looks like the post here might have been slightly off topic :)

    Have you checked this thread as well: https://community.ibm.com/community/user/integration/discussion/can-we-able-to-send-a-file-from-multipartform-data-to-a-ftp-server-and-a-database-at-a-time-using-ibm-apiconnect-v10#bm3e264504-dcbc-4ab8-a7c9-cdf0aaf84195

    it adressess some issues with multipart messages.



    ------------------------------
    Regards
    Matthias Blomme
    ------------------------------



  • 7.  RE: How can we upload a PDF file in IBM API Connect using rest API?

    Posted Tue February 21, 2023 04:54 AM

    Hi Matthias Blomme,

    Actually the file is uploaded in Developer Portal, and so the developer is not providing the file name.

    So while we are trying to trace the values we are facing the issue as we are not able to get the file name.

    Please suggest if you have any.

    Thanks

    Nrusingha Sahoo



    ------------------------------
    Nrusingha Sahoo
    ------------------------------