How to upload images to a POST request

Good afternoon,

I am relatively new to APIs and Postman and whilst I have been able to nut out most things, there is something I cannot quite understand.

Take the CURL command below:

curl -X POST https://example.com/site/products \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "name": "Product name",
  "sale_price": "25.50",
  "description": "Body of text",
  "images": [
    {
      "src": "http://site.com/images/image1.jpg"
    },
    {
      "src": "http://site.com/images/image2.jpg"
    }
  ]
}'

Using Postman, I can easily create a new product in the receiving system (called “Product name” or any other information that doesn’t have ‘deeper’ levels), but I am not sure how to use the “image” syntax within Postman to upload 1 or 2 or however-many images to the system.

What format do I use for the key and value, please?

Could somebody point me in the right direction - any help much appreciated.

Greg

Hi there, not sure if this is what you need, but you can select a File as the attribute type in the body. Screen Shot 2020-08-24 at 12.51.09

Also, its is good form to use a descriptive subject… something like ‘How to upload images’ or something like that will help others with the same issue as well as make it more likely for someone to help. See the list of other subjects in the Forum for examples.

Hi MrRoyce101,

Thankyou for answering my post. I suppose I could have worded it differently, but it was more of a parsing question than about the image per se - I’ll be more aware of this next time.

I need to keep the command “self-contained” so the option of having an external file from Postman would not work in my situation. I simply want to see the entire single CURL command so I can apply it to my solution - as I am only using Postman for testing.
Any way I can do this in a single line instead of external file?

Cheers,
Greg

You could encode the file to base64 and send it in the curl command that way.

https://base64.guru/converter/encode/file

Hi Allen,

Thanks for that suggestion. I could encode files and send them although with the minimal data being transferred to the host, I am hoping to stick to having it “self contained” in a single command.
I’l work with this option too though. :slight_smile:

Greg

Could you elaborate more on what exactly you want?

You want to use a file, but also have it self-contained?

I’m happy to help any way I can, I just want to make sure I understand the ask.

Hi Allen,

Thanks for following up.

When I say self contained, I meant having a single command for the CURL command - so all the data is is there - not having to refer to an external file to refer-to/attach.

The reason I sent my query by this forum was to get the CURL syntax correct in Postman (which is why I mainly use Postman. Testing). The final command syntax is written in Filemaker but needed to understand the native CURL syntax before I could use it.

I have made progress on this overnight (amazing what you can achieve when you don’t sleep. :slight_smile: ) and am close.

Thank you for your (and others’) help on this. Further testing and Googling the stuffing out of this I might have cracked it by the end of today.

Cheers Allen.

1 Like