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

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

Related

Upload file using trest client component with post method

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.

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 I upload a file with metadata to jfrog artifactory with curl

I upload a file like this:
curl -u ${CREDS} --upload-file ${file} ${url}
Is there a way to add a body or headers that will set some metadata for the file? Like build number.
You can actually deploy artifacts with properties to Artifactory OSS using matrix parameters, for example:
curl -uadmin:password -T file.tar "http://localhost:8081/artifactory/generic-local/file.tar;foo=bar;"
And get the artifact properties using REST API, for example:
curl -uadmin:password "http://localhost:8081/artifactory/api/storage/generic-local/file.tar?properties"
Viewing properties from the UI and other features are limited to the Pro edition.
Seems this is a pro feature. Documentation: Set Item Properties
PUT /api/storage/{repoKey}{itemPath}?properties=p1=v1[,v2][|p2=v3][&recursive=1]
Not helping me :-/

How to use JSON in OrientDB HTTP command request

I'm using orientdb-community-2.2-alpha and I'm trying to use JSON payloads with the HTTP command API (as in calling http://<host>:<port>/command/<database>/sql) and I simply can't figure out how to do it. All I get is an OCommandExecutorNotFoundException saying Cannot find a command executor for the command request: sql.<whatever JSON I tried here> no matter what I try.
I'm not providing an example of what I've tried as I'm not trying to do any one specific thing; I would just like to see a working curl example of how to post a generic command request using a JSON payload.
I can use JSON with batch requests just fine, it's just the command API that I can't get to work.
You can try with Postman plugin

Unable to understand the cURL invocation

I am currently using jpmml openscoring REST API..
I have successfully installed Maven and built the uber-JAR file and I am also able to access
http://localhost:8080/OpenScoring/rules.pmml
I am confused with the instructions given at
https://github.com/jpmml/openscoring.
It says the sample curl invocation is
curl -X GET htttp://localhost:8080/openscoring/model
but I am getting a 404 error when I try to implement this. What does model mean here?
I am getting an output when I implement this:
curl -X GET htttp://localhost:8080/Openscoring/rules.pmml
The /model/ part of the path identifies the resource type. The general formula for the path component of Openscoring service URLs is /<context path>/<resource type>/<resource identifier>/<action>
In your case (assuming that the model identifier is rules.pmml), the correct path component would be /openscoring/model/rules.pmml.
I was getting a 404 error as I did not put my rules.pmml file in the directory which my command prompt pointed to.(This was a very silly mistake)
And thanks to the user Anik Islam Abhi in the comments, I found out what model in the invocation
curl -X GET htttp://localhost:8080/openscoring/model meant.
model is just an Endpoint of the REST source but not a directory in the openscoring folder or any kind of path.