Add files via upload
This commit is contained in:
@@ -4,6 +4,10 @@ import java.io.IOException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -23,10 +27,26 @@ public class FromPDFController {
|
||||
}
|
||||
|
||||
@PostMapping("/convert-from-pdf")
|
||||
public byte[] convertToImage(@RequestParam("fileInput") MultipartFile file,
|
||||
public ResponseEntity<byte[]> convertToImage(@RequestParam("fileInput") MultipartFile file,
|
||||
@RequestParam("imageFormat") String imageFormat) throws IOException {
|
||||
byte[] pdfBytes = file.getBytes();
|
||||
return PdfUtils.convertFromPdf(pdfBytes, imageFormat);
|
||||
//returns bytes for image
|
||||
byte[] result = PdfUtils.convertFromPdf(pdfBytes, imageFormat.toLowerCase());
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.parseMediaType(getMediaType(imageFormat)));
|
||||
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
|
||||
ResponseEntity<byte[]> response = new ResponseEntity<>(result, headers, HttpStatus.OK);
|
||||
return response;
|
||||
}
|
||||
|
||||
private String getMediaType(String imageFormat) {
|
||||
if(imageFormat.equalsIgnoreCase("PNG"))
|
||||
return "image/png";
|
||||
else if(imageFormat.equalsIgnoreCase("JPEG"))
|
||||
return "image/jpeg";
|
||||
else if(imageFormat.equalsIgnoreCase("GIF"))
|
||||
return "image/gif";
|
||||
else
|
||||
return "application/octet-stream";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user