It's all about the answers!

Ask a question

How do I upload an image to ETM via a POST request using REST API?


Aaron Szymanski (11) | asked Jul 07, 3:33 p.m.

 I have been attempting to upload a .png image to ETM using a POST request via REST API. I am returning a 201, as well as a slugID, which tells me that it is working. The problem is that when I try to then view the image, using what is assumed to be the correct URL (the one returned in the response), there is nothing there. I have followed the footnote 6 in the ETM REST API documentation, but apparently I'm still doing something wrong. Possibly using the wrong URI to POST? I'm not really sure and can't seem to find any existing solutions out there, though I have found similar type issues/questions.


Thank you. 

ETM version 7.0.2

One answer



permanent link
Aaron Szymanski (11) | answered Aug 30, 6:56 p.m.

 Figured something out. My solution using python for posting a test script with multiple images:


........
for idx, name in enumerate(dict['names']):
   with open(newpath + '/' + name, mode='rb') as file: 
      name_img = name
      files = {'image': (name_img, file, 'multipart/mixed',{Expires': '0'})}
      url = <resourceurl>
      response = session.post(url, file=files)
........

Look at ETM API documentation for <resourceurl> definition and example. The resource type is "attachment."

Your answer


Register or to post your answer.