I'm writing a component to upload some files to AWS/S3. How can I detect the content-type of the upload form inputFile or from a Blob of the file in Apex?

 req.setHeader('Content-type', getInputFileContentType.ContentType);

What can I use in place of getInputFileContentType?


If I get it from the blob instance of the file (fileBlob.ContentType) I get this error:

Initial term of field expression must be a concrete SObject: Blob (Line: 273)

What's going on?

  • Where is the blob coming from? Visualforce, callout, attachment record, static resource...? – sfdcfox Jun 27 '16 at 23:20
  • Sorry, from parsing a form. I think I've got a fix though. – okay56k Jun 27 '16 at 23:35

So you need a getter and a setter in the controller:

public String contentType { get; set; }

And a matching attribute in the inputFile:

<apex:inputFile id="postFileId" fileName="{!fileName}" fileSize="{!fileSize}" value="{!fileBlob}" contentType="{!contentType}" />

Ta da.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.