Send file with POST request

I have a servoy-app and an external service, so-called, store-file-service.

In store-file-service (written in Spring), I have a controller that takes responsibility of storing file via a POST request with request param is “file-param” and the paramter is MultipartFile.

In servoy-app, to send a POST request with the parameterName is “file-param”, I have the following code

	var client = plugins.http.createNewHttpClient();
	var poster = client.createPostRequest("http://localhost:8080/api/store-file");
	
	// configure header
	poster.addHeader("Content-Type", "multipart/form-data; boundary=any")
	// ===

	// configure parameter
	poster.addFile("file-param", "filename", myJsFile);
	// ===
	
	var response = poster.executeRequest();	
	response.close();

From servoy-app, everything seems to work. But from store-file-service, I got log info

MissingServletRequestPartException: Required part ‘file-param’ is not present.

This makes me confused because I already declared the parameterName while addFile as “file-param”. Is there any wrong with my configuration in servoy-app?

Testing store-file-service with postman works well as expected.

Hi,

I assume you are using a recent version of Servoy.
For me this code works:

var client = plugins.http.createNewHttpClient();
   var poster = client.createPostRequest("http://localhost:8080/api/store-file");
   
   // configure header
   poster.addHeader('Accept', 'application/json')
   // ===

   // configure parameter
   poster.addFile("file-param", "filename", myJsFile, 'application/octet-stream');
   poster.forceMultipart(true);
   // ===
   
   var response = poster.executeRequest();   
   response.close();

The above is processed by a web service written in Servoy and using the rest-ws plugin.

An easy way to test incoming requests is this service: https://requestbin.com

Hope this helps

Dear Marc,

Wonderful, It works like a charm!

Thanks for your quick feedback :-)