Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pem-File causes "File extension does not match known MIME type" #47

Open
schrattenholz opened this issue May 4, 2021 · 7 comments
Open

Comments

@schrattenholz
Copy link

Hi I added pem in the setAllowedExtensions and added the mime type to the mimevalidator
SilverStripe\MimeValidator\MimeUploadValidator: MimeTypes: pem: - 'application/x-pem-file'
still getting "the unkown mimetype error"

@emteknetnz
Copy link
Member

A .pem file seems like the sort of thing that should not be uploaded via a webapp

What's the use case here?

@schrattenholz
Copy link
Author

schrattenholz commented May 5, 2021 via email

@obj63mc
Copy link

obj63mc commented Oct 4, 2023

While not PEM file related, I am trying to upload a 3d model, glb and gltf files to the CMS for a project.

I have added the following to my yaml config -

SilverStripe\Assets\File:
  allowed_extensions:
    - svg
    - gltf
    - glb
SilverStripe\MimeValidator\MimeUploadValidator:
  MimeTypes:
    svg:
      - 'image/svg+xml'
      - 'image/svg'
    gltf:
      - 'model/gltf+json'
      - 'model/gltf-binary'
    glb:
      - 'model/gltf+json'
      - 'model/gltf-binary'

But when I go to upload the file in the CMS I get the following error -

File type does not match extension (.glb)

If I look at the network request - I can see in the formdata that the file mime type is

-------WebKitFormBoundaryoELi7TUVmguoAA8c
Content-Disposition: form-data; name="Upload"; filename="riviera.glb"
Content-Type: model/gltf+json

Any ideas on how to actually allow SS to allow uploads of non standard files as this doesn't seem possible even when following the docs at - https://docs.silverstripe.org/en/5/developer_guides/files/allowed_file_types/

This is testing with SS5

@emteknetnz
Copy link
Member

Seems like it's failing in MimeUploadValidator::isValidMime() - I'd recommend you put a debug breakpoint in there to isolate what's causing the mime validation to fail

@obj63mc
Copy link

obj63mc commented Oct 5, 2023

So when testing, and hard breaking, the mime type for some reason returning as application/octet-stream

I added that to the possible options and was able to upload it now. But my main question is why would SS see the file as that mime type when the posted upload clearly has the mime type set as model/gltf+json. Not sure if this is a webserver issue, SS issue or even OS issue. This was debugged on apache/php 8.2/mac OS

If I had to guess the original bug submitter was running into a similar issue where even though the proper mime type was posted and configured, it was being read as something else.

@emteknetnz
Copy link
Member

emteknetnz commented Oct 5, 2023

Not sure. The mimevalidator uses the PHP Fileinfo extension:

mime type set as model/gltf+json

Was that what finfo() was returning? Or was finfo() returning application/octet-stream?

@obj63mc
Copy link

obj63mc commented Oct 9, 2023

So the web browser POST request was showing the proper mime type posted of model/gltf+json.

When outputting the value of the $foundMime variable from line 68 - https://github.com/silverstripe/silverstripe-mimevalidator/blob/3/src/MimeUploadValidator.php#L68 it was marked as application/octet-stream

Trying to research this, it looks like it simply uses the mime types configured via your server/webserver so in this case what Apache would return in my instance. If I add the following to my Apache config though -

AddType model/gltf+json .gltf
AddType model/gltf-binary .glb

the fileinfo is still returning application/octet-stream. Since this is a core php function clearly not a SS issue but if you have any ideas on this is greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants