Chilkat Online Tools

autoit / PrestaShop Webservice Product Resource A-Z / 6 - Upload image

Back to Collection Items

; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oHttp = ObjCreate("Chilkat_9_5_0.Http")
Local $bSuccess

$oHttp.BasicAuth = True
$oHttp.Login = "{{webservice_key}}"
$oHttp.Password = "password"

$oReq = ObjCreate("Chilkat_9_5_0.HttpRequest")
$oReq.HttpVerb = "POST"
$oReq.Path = "/api/images/products/1"
$oReq.ContentType = "multipart/form-data"
$bSuccess = $oReq.AddFileForUpload2("image"," path to file","application/octet-stream")

$oReq.AddHeader "Expect","100-continue"

Local $oResp = $oHttp.SynchronousRequest("localhost",8080,True,$oReq)
If ($oHttp.LastMethodSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite($oResp.StatusCode & @CRLF)
ConsoleWrite($oResp.BodyStr & @CRLF)

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": [
  ]
}