Back to Collection Items
var
http: HCkHttp;
success: Boolean;
req: HCkHttpRequest;
resp: HCkHttpResponse;
begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
CkHttp_putBasicAuth(http,True);
CkHttp_putLogin(http,'{{webservice_key}}');
CkHttp_putPassword(http,'password');
req := CkHttpRequest_Create();
CkHttpRequest_putHttpVerb(req,'POST');
CkHttpRequest_putPath(req,'/api/images/products/1');
CkHttpRequest_putContentType(req,'multipart/form-data');
success := CkHttpRequest_AddFileForUpload2(req,'image',' path to file','application/octet-stream');
CkHttpRequest_AddHeader(req,'Expect','100-continue');
resp := CkHttp_SynchronousRequest(http,'localhost',8080,True,req);
if (CkHttp_getLastMethodSuccess(http) = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkHttpRequest_Dispose(req);
Curl Command
curl -X POST
-u '{{webservice_key}}:password'
-H "Content-Type: application/json"
--form 'image=@"/path/to/file"'
https://localhost:8080/api/images/products/1
Postman Collection Item JSON
{
"name": "6 - Upload image",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "image",
"type": "file",
"src": [
]
}
]
},
"url": {
"raw": "{{webservice_url}}/api/images/products/{{product_id}}",
"host": [
"{{webservice_url}}"
],
"path": [
"api",
"images",
"products",
"{{product_id}}"
]
}
},
"response": [
]
}