Skip to content

Instantly share code, notes, and snippets.

@rbaul
Last active June 29, 2023 09:43
Show Gist options
  • Save rbaul/96380bea8e90bb8f4b5b25334f713f28 to your computer and use it in GitHub Desktop.
Save rbaul/96380bea8e90bb8f4b5b25334f713f28 to your computer and use it in GitHub Desktop.
MULTIPART_FORM_DATA_VALUE: Client (Python) - Server (Spring Boot)
import json
import requests
import logging
logging.basicConfig(format='%(asctime)s :: %(levelname)s :: %(funcName)s :: %(lineno)d :: %(message)s',
level=logging.INFO)
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
multipart_form_data = {
'document': ('enviroments.txt', open('C:\\Roman\\enviroments.txt', 'rb'), 'application/octet-stream'),
'employee': (None, json.dumps({'name': '1234', 'address': 'address'}), 'application/json')
}
post = requests.post('http://localhost:9000/api/v1/random-data/request-part/employee/object',
files=multipart_form_data)
logging.info('Result: %s', post)
@PostMapping(path = "/request-part/employee/object", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
public Person requestPartObject(@RequestPart Person employee, @RequestPart MultipartFile document) {
return employee;
}
public record Person (String name, String address) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment