web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Mime Type Check not wo...
Power Pages
Unanswered

Mime Type Check not working as expected

(0) ShareShare
ReportReport
Posted on by 5

Hi All, 

 

I have a some strange behaviour taking place on a basic form I have created on PowerApps Portals. 

 

I have set up the form upload to only accept PDFs. While it does block any file extension other than PDF, when I changed the file extension of an excel file to .pdf, this file was allowed. Is there something I'm missing here? Is this check actually on the file Mime type or just on file extension?

 

johncosgrove_0-1628182112851.png

 

Any guidance on this would be appreciated, as I cannot figure out what is happening and there doesn't seem to be anyone else who has had this problem!

 

Thanks, 

 

John

 

Categories:
I have the same question (0)
  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    on at

    Hi @johncosgrove,

    Actually, the MIME type is used by your browser to decide how to present some data (or the server on how to interpret received data), the file extension is commonly used for your OS to decide what program to open a file with.

    One file extension maps to at most one MIME type. One MIME type maps to zero or more file extensions. A good example is image/jpeg, which maps to both .jpg and .jpeg.

    In a word, the file extension is not always reliable, so is the MIME type, both can be forged. Just like you tested on your side, that you change your file extension from an excel file to .pdf, which fools the MIME type allowed setting.

    Here is a common MIME types list and I found that the agreed MIME type recognized file extension is ".pdf" which means that if you change the file extension from ".xls" to ".pdf", its MIME type will be changed from "application/vnd.ms-excel" to "application/pdf"

    vqiaqimsft_0-1628220696771.png

    vqiaqimsft_2-1628220794954.png

    Short to say that the issue happened to you is indeed an known issue. There is no guaranteed way to do it at time of selection.

    You could use JavaScript. Take in consideration that the big problem with doing this with JavaScript is to reset the input file. Well, this restricts to only JPG (for PDF you will have to change the mime type and the magic number😞

    <form id="form-id">
     <input type="file" id="input-id" accept="image/jpeg"/>
    </form>
    
    <script type="text/javascript">
     $(function(){
     $("#input-id").on('change', function(event) {
     var file = event.target.files[0];
     if(file.size>=2*1024*1024) {
     alert("JPG images of maximum 2MB");
     $("#form-id").get(0).reset(); //the tricky part is to "empty" the input file here I reset the form.
     return;
     }
    
     if(!file.type.match('image/jp.*')) {
     alert("only JPG images");
     $("#form-id").get(0).reset(); //the tricky part is to "empty" the input file here I reset the form.
     return;
     }
    
     var fileReader = new FileReader();
     fileReader.onload = function(e) {
     var int32View = new Uint8Array(e.target.result);
     //verify the magic number
     // for JPG is 0xFF 0xD8 0xFF 0xE0 (see https://en.wikipedia.org/wiki/List_of_file_signatures)
     if(int32View.length>4 && int32View[0]==0xFF && int32View[1]==0xD8 && int32View[2]==0xFF && int32View[3]==0xE0) {
     alert("ok!");
     } else {
     alert("only valid JPG images");
     $("#form-id").get(0).reset(); //the tricky part is to "empty" the input file here I reset the form.
     return;
     }
     };
     fileReader.readAsArrayBuffer(file);
     });
     });
    </script>

    For a complete list of mime types see Wikipedia.

    For a complete list of magic number see Wikipedia.

    Hope this could help you at some degree.

  • ragavanrajan Profile Picture
    7,044 Most Valuable Professional on at

    Hi @johncosgrove 

     

    Please confirm the excel file you have changed the extension is on your local machine or in the portal? 

    In general, if you change the extension from .xls/.xlsx to .pdf windows will take this as PDF. 

     

    More info: 

    A MIME type is a label used to identify a type of data. It is used so the software can know how to handle the data. It serves the same purpose on the Internet that file extensions do on Microsoft Windows

     

    Please click here 

     

    Hope it helps. 
    ------------

    If you like this post, give it a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.

     

  • johncosgrove Profile Picture
    5 on at

    Thank you @v-qiaqi-msft and @ragavanrajan  for your responses. 

     

    While I had hoped it was something I was doing and not standard behaviour, I am glad I have clarity now. 

     

    Thanks, 

     

    John 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard