Last active
June 29, 2023 09:43
-
-
Save rbaul/96380bea8e90bb8f4b5b25334f713f28 to your computer and use it in GitHub Desktop.
MULTIPART_FORM_DATA_VALUE: Client (Python) - Server (Spring Boot)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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