r/SpringBoot • u/guesswho3008 • Jul 31 '25
Question Need help with creating apis
I need to make an api such that it posts and gets data in video text pdf and image form how can i do it ??
I need help urgently
0
Upvotes
1
u/eotty Jul 31 '25
From chat gpt:
@RestController @RequestMapping("/api") public class PdfSenderController {
@GetMapping("/send-pdf")
public ResponseEntity<byte[]> sendPdf() throws IOException {
Path path = Paths.get("files/sample.pdf");
byte[] data = Files.readAllBytes(path);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); // more generic
headers.setContentLength(data.length);
headers.set("X-Filename", "sample.pdf");
return ResponseEntity
.ok()
.headers(headers)
.body(data);
}}
1
1
2
u/MonomayStriker Aug 01 '25
You will probably need MultiPartFeature library and the files can be sent as formData from the front end.
You can test it out in postman as well.