I have a follow up question for another question I asked Formdata isnt working in Apex
/tldr I'm using an api that uses formdata but now I need to add a pdf file to the formdata
So what I'm trying to do is to use a visualforce page as the file (it uses the renderAs='Pdf' tag). When looking at how to do it on postman it looks like this (even when I add my file manually).
Content-Disposition: form-data; name="Files"; filename="[PROXY]"
Content-Type: <Content-Type header here>
(data)
------WebKitFormBoundary7MA4YWxkTrZu0gW--
And when trying to add the visualforce page to the formdata I tried
PageReference pdf = new pagereference('/apex/renderAsPdf');
Blob file;
try {
file = pdf.getContentAsPDF();
System.Debug('Successful'+file);
} catch (Exception e) {
file = Blob.valueOf('data');
system.debug('Error'+ e);
}
body += 'name=\"Files\"; filename=\"lease.pdf\"\r\n\r\n'+EncodingUtil.base64Encode(file)+'\r\n';
body += '------WebKitFormBoundary7MA4YWxkTrZu0gW--';
I also tried doing files by itself and tried putting the blob into a content version and adding that
ContentVersion CV = new ContentVersion();
CV.Title = 'L.pdf';
CV.PathOnClient = 'L.pdf';
CV.VersionData = file;
body += 'name=\"Files\"; filename=\"lease.pdf\"\r\n\r\n'+CV+'\r\n';
body += '------WebKitFormBoundary7MA4YWxkTrZu0gW--';
But everything gives me a 422 error::"Unsupported file(s). Supported file formats are PDF, Word, PNG, JPEG, and JPG"