Original Message:
Sent: Wed February 15, 2023 11:03 AM
From: Matthias Blomme
Subject: How can we upload a PDF file in IBM API Connect using rest API?
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
Original Message:
Sent: Wed February 15, 2023 06:27 AM
From: Nrusingha Sahoo
Subject: How can we upload a PDF file in IBM API Connect using rest API?
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
Original Message:
Sent: Wed February 15, 2023 06:09 AM
From: Matthias Blomme
Subject: How can we upload a PDF file in IBM API Connect using rest API?
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
Original Message:
Sent: Wed February 15, 2023 03:47 AM
From: Nrusingha Sahoo
Subject: How can we upload a PDF file in IBM API Connect using rest API?
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':
description: success
requestBody:
content:
application/octet-stream:
schema:
type: string
format: binary
parameters:
- name: pdfName
in: path
schema:
type: string
required: true
description: the name of the pdf
------------------------------
Nrusingha Sahoo
Original Message:
Sent: Wed February 15, 2023 02:23 AM
From: Matthias Blomme
Subject: How can we upload a PDF file in IBM API Connect using rest API?
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:
openapi: 3.0.0
info:
title: PDF
version: 1.0.0
description: PDF
servers:
- url: /pdf/v1
paths:
/upload/{pdfName}:
post:
responses:
'200':
description: success
requestBody:
content:
application/octet-stream:
schema:
type: string
format: binary
parameters:
- name: pdfName
in: path
schema:
type: string
required: true
description: the 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
Original Message:
Sent: Tue February 14, 2023 11:18 PM
From: Nrusingha Sahoo
Subject: How can we upload a PDF file in IBM API Connect using rest API?
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
------------------------------