Upload file using trest client component with post method - talend

trying to upload file using trest client component with post method.
Able to upload file using postman post call.
Same thing is not working in Talend.
Getting 415 error.
trying to upload file using trest client component with post method.
Able to upload file using postman post call.
Same thing is not working in Talend.
Getting 415 error.

In tRestClient, Query parameters are string parameters, so even if you pass your file path in the "file" parameter, only the file path is passed as a string to your api and the actual file will not be uploaded.
You can upload a file using tFileFetch component, by checking "Upload file" in the advanced settings.

Related

Jmeter Importing using .xlsx file extension

Hello can someone help me import .xlsx on Jmeter, I tried to use this configuration unfortunately it doesn't work. Your response is highly appreciated. Thank you so much in advance.
Screenshot:
File Location
1st Payload/Request
2nd Payload Request:
Header
Response:
If you're using "Files upload" tab and your server expects multipart/form-data content type you should tick the corresponding box in JMeter's HTTP Request sampler:
Going forward be informed that it's possible to record the file upload request from your browser (or other application) using JMeter's HTTP(S) Test Script recorder, just make sure to copy the file(s) you will be uploading to JMeter's "bin" folder so JMeter could properly generate the relevant HTTP Request sampler and the HTTP Header Manager.
More information: Recording File Uploads with JMeter

Jmeter - How load HTTP Body text from file directory

I have multiple HTTP body data saved in couple of text files in one directory. I need to load that HTTP body data from those files which in that directory into SOAP request via jmeter.
The easiest way to get the file names into a JMeter Variable is using Directory Listing Config plugin
Once done you can reference each and every file content using __FileToString() function like:
${__FileToString(${body},,)}
This way each virtual user will send the content of the next file on each iteration:

Python flask: forward POST to external API

I am building a microservice for the Camunda rest API using python flask and flask_restplus, python 3.7.0. Camunda is running in a docker container, available via localhost, port 8080. All GET requests to my microservice are being forwarded to the Camunda API via redirect, which is working perfectly fine.
POST requests (tested via postman, as suggested in the official tutorial) are not being forwarded properly using
redirect(camunda_api_url)
or
request.post(camunda_api_url)
The POST request via postman is done using
Header: Content-Type: multipart/form-data
Body: upload File Object (somefile.bpmn)
When I do the POST to the Camunda REST-API directly, everything works just fine, but when I try to redirect my post via my microservice, I get status code 200, but the file isn't being uploaded.
Debugging at my endpoint I can see that the file is being received:
print(request.files['upload'])
<FileStorage: 'somefile.bpmn' ('application/octet-stream')>
Thus the file is being transmitted successfully, but the redirect doesn't work.
My endpoint method looks like this:
def post(self):
print(request.files['upload'])
test = requests.post(host_prefix + 'deployment/create', files=request.files)
print(test.status_code)
Modifying the request.post via
data=request.files
data=request.files['upload']
or omiting data completely
always results in the file not being uploaded.
Trying redirect via
redirect(host_prefix + 'deployment/create', code=307)
also results in the file not being uploaded.
How can I redirect this post request properly to the Camunda API ?
This is not a question about the Camunda API rather than how to redirect a POST request to a foreign endpoint properly.
P.S.: I created my api and endpoints like this:
app = Flask(__name__)
api = Api(app, version='0.1', title='BPMN-API', description='A BPMN-API for Camunda, implemented in python')
...
api.add_resource(CreateDeployment, api_prefix + 'deployment/create', methods=['POST'])
OK, I solved this problem by using:
requests.post(camunda_api_url, files={file_name:request.files['upload'].read()})
where camunda_api_url is the endpoint at the Camunda REST engine, file_name is the name of the file being uploaded, AND by adding a
get-method,using simply:
def get(self):
camunda_api_url = "http://localhost:8080/engine-rest/deployment/create"
return redirect(camunda_api_url)
Without the get method the post doesn't work.
-> setting topic to solved. :)
By using requests library it is very easy. The example shows multiple file uploads with same key and with other form data as well. The images are coming from a form with the key named 'images'
The example gets file list from a form with the key 'images' and forward that files to another URL or API.
images = request.files.getlist('images')
files = []
for image in images:
files.append(("images", (image.filename, image.read(), image.content_type)))
r = requests.post(url=api_urls.insert_face_data_url, data={"apikey": apikey, "faceid": faceid},
files=files)

How to upload a file using REST API Put method using JMeter

Context of my query:
Need to test REST API Put method for uploading a file
tool to be used is JMeter.
I can successfully perform the above operation using POSTMAN tool but its not working in JMeter.
Here are the JMeter Request Details;
method: PUT
Path:path
HEADER
Content-Type= multipart/form-data; boundary=----WebKitFormBoundary${random}
BODY DATA
------WebKitFormBoundary${random}
Content-Disposition: form-data; name="fileUpload"; filename="C:\temp\abc.zip"
Content-Type: application/octet-stream
------WebKitFormBoundary${random}--
RESULTS:
{"success":false,"errorMessages":"Request did not include an attachment"}
Response code = 400
Appreciate if anyone can help or provide a better way to upload a file using PUT method.
Thanks,
AB
Use MIME Type: application/zip
Your File Upload settings should look like this in JMeter:
My expectation is that you simply don't pass the file you are trying to upload along with the request. If you are building the request manually you will need to add the body of the file to your request using i.e. __FileToString() function. Check out Testing REST API File Uploads in JMeter article for more details.
Also given your request works in Postman you should be able to capture it using JMeter's HTTP(S) Test Script Recorder
Copy the file you will be uploading using Postman to the "bin" folder of your JMeter installation
Start JMeter's Proxy server. Refer JMeter Proxy Step by Step guide to learn how to do it.
Start Postman using JMeter's HTTP(S) Test Script Recorder as a proxy by passing --proxy-server option to it like:
C:\Users\your_user_name\AppData\Local\Postman\app-x.x.x\Postman.exe --proxy-server=localhost:8888
Execute your request in Postman
JMeter will store the captured request under Test Plan -> Thread Group -> Recording Controller

How do you upload a image file and a json with curl?

I'm trying to use command line curl to test an API. The call takes in some parameters and a image file. Is there a way for me to specify the parameters using a json file, and make the request via curl so both the image file and the json file gets uploaded to the server?
Check the curl documentation here
In the POST (HTTP) part you'll find the answer to your question.
You need to use the -F parameter