Sending an Image from Mendix to other application API (Images are uploaded using a multipart form encoded POST)

0
For an API i need to send images as a multipart form encoded POST. I'm not sure how I go about doing this in Mendix. They show an example post as follows:   POST /API/Account/{id}/Item/{id}/Image Accept: application/xml Content-Type: multipart/form-data; boundary=25112bca3fa7474e9874f9e8654c27aa --25112bca3fa7474e9874f9e8654c27aa Content-Disposition: form-data; name="data" <Image> <filename>2014 red racer.jpg</filename> <description>Our new 2014 Racer model in Red!</description> </Image> --25112bca3fa7474e9874f9e8654c27aa Content-Disposition: form-data; name="image"; filename="2014 red racer.jpg" Content-Type: image/jpeg .... Image data .... --25112bca3fa7474e9874f9e8654c27aa--   But I am not sure where I actually put my image data/file/base64 encoded string. What would be my first step in achieving this POST message? When sending the data via the REST module I get the following error while using the post method and ''Submit as form data = true'' while putting in a filedocument:   [HTTP Request: POST 'https://api.merchantos.com/API/Account/xx/Item/59/Image?oauth_token=xx' --> Response status: 405 Method Not Allowed, ETag: null, body: '{"httpCode":"405","httpMessage":"Method Not Allowed","message":"PUT, POST require an input body.","errorClass":"Exception"}'  
asked
1 answers
2

Have a look at this question: POSTing a file to a https REST service

POSTing multipart form data isn't possible with the platform without an App Store module. This will be included in the platform in the near future. You can use the REST Services module from the App Store to send multipart form data.

Here is a link to the documentation of the REST Services module: Consuming operations that work with files

 

21-11-2016:

After gaining access to a test project, this is what the request looks like:

--7AS5qM4ES3qmVzcwmGL8LZoS8BTkvuPSdIuKf1
Content-Disposition: form-data; name="{FILENAME_UPLOADED_IMAGE}"; filename="{FILENAME_UPLOADED_IMAGE}"
Content-Type: application/octet-stream; charset=ISO-8859-1
Content-Transfer-Encoding: binary

BINARY
--7AS5qM4ES3qmVzcwmGL8LZoS8BTkvuPSdIuKf1
Content-Disposition: form-data; name="Thumbnail_Image"
Content-Type: application/octet-stream; charset=ISO-8859-1
Content-Transfer-Encoding: binary

BINARY
--7AS5qM4ES3qmVzcwmGL8LZoS8BTkvuPSdIuKf1
Content-Disposition: form-data; name="PublicThumbnailPath"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

null
--7AS5qM4ES3qmVzcwmGL8LZoS8BTkvuPSdIuKf1
Content-Disposition: form-data; name="__UUID__"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

3bdf5104-38cb-4a31-b71e-67a6c8513211
--7AS5qM4ES3qmVzcwmGL8LZoS8BTkvuPSdIuKf1
Content-Disposition: form-data; name="TestImage_LightspeedSettings"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

null
--7AS5qM4ES3qmVzcwmGL8LZoS8BTkvuPSdIuKf1
Content-Disposition: form-data; name="LightspeedID"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

59
--7AS5qM4ES3qmVzcwmGL8LZoS8BTkvuPSdIuKf1
Content-Disposition: form-data; name="__FileName__"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

1
--7AS5qM4ES3qmVzcwmGL8LZoS8BTkvuPSdIuKf1--

while it should look like:

POST /API/Account/{id}/Item/{id}/Image
Accept: application/xml
Content-Type: multipart/form-data; boundary=25112bca3fa7474e9874f9e8654c27aa
--25112bca3fa7474e9874f9e8654c27aa
Content-Disposition: form-data; name="data"
<Image>
<filename>2014 red racer.jpg</filename>
<description>Our new 2014 Racer model in Red!</description>
</Image>
--25112bca3fa7474e9874f9e8654c27aa
Content-Disposition: form-data; name="image"; filename="2014 red racer.jpg"
Content-Type: image/jpeg
.... Image data ....
--25112bca3fa7474e9874f9e8654c27aa--

 

in case anybody needs this in the future. I changed the java file and added the code below just before the call to client.executeMethod(request);. I have to admit that this is kind of dirty, since you shouldn't directly write to System.out

if (request instanceof PostMethod) {
	PostMethod pm = (PostMethod)request;
	pm.getRequestEntity().writeRequest(System.out);
}		

int status = client.executeMethod(request);

 

22-11-2016:

So it seems that what you are trying to achieve isn't possible without modifying the REST module

answered