PDF upload from MultipartFile
Hello,
I have a server that uses Cloudinary for uploading PDF files. The resource comes as MultipartFile. However, when i want to get back the file comes with N/A format. I couldn't find a way to specify that the fileFormat is PDF although I know that always this will be a PDF. Here is the snippet.
I used the method .getBytes because I don't want to store files on server (not even temprarily). Is there a way to specify that the file that i upload is PDF. (When I load a PDF from Cloudinary I can see it in browser. That's the result that I want to achieve.) I uploaded a photo of the code in case the code style is wrong formatted.

public String uploadApplicantCV(Long applicantId, MultipartFile cvFile) throws NotValidContactException, NotValidCVException, NotValidCVUploadException {
String CVUrl = null;
Contact contact = findContactByApplicantId(applicantId);
CV cv = findCVByContactId(contact.getId());
try {
Map uploadParams = ObjectUtils.asMap("resource_type", "raw");
Map uploadResult = cloudinary.uploader().upload(cvFile.getBytes(), uploadParams);
CVUrl = (String) uploadResult.get("url");
String public_id = (String) uploadResult.get("public_id");
cv.setUrl(CVUrl);
cv.setPublic_id(public_id);
cv.setDeleted(false);
} catch (IOException e) {
// throw new NotValidCVUploadException(e.getMessage());
throw new NotValidCVUploadException("Error when trying to upload the CV");
}
cvRepository.saveAndFlush(cv);
return CVUrl;
}
-
Hi
If I understand you correctly you are able to see the uploaded file correctly, but you are not able to view it in the browser but rather download it and then view it.
If that is the case then if you are sure that the file will be a pdf file, you can upload it as type "image" instead of "raw", to view it in the browser.
If that is not the case, kindly open a request with us at support@cloudinary.com and elaborate on the flow that you are perfroming in order for us to take a closer look.
0
Post is closed for comments.
Comments
1 comment