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
    Commented Jun 27, 2016 at 23:20
  • Sorry, from parsing a form. I think I've got a fix though.
    – t56k
    Commented Jun 27, 2016 at 23:35

1 Answer 1


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .