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

BUGFIX: Detect Content-Type in GcsStorage #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jrenggli
Copy link
Contributor

When uploading a resource to GCS storage the Content-Type is explicitly
defined in metadata options.

'metadata' => [
    'contentType' => $resource->getMediaType()
]

However getMediaType() is always returning the fallback value
application/octet-stream as it's logic is based on using the filename
to determine the Content-Type. At this point the filename consists only
of a sha1 or a random value.

PHP's fileinfo extension has functions to detect a Content-Type based on
file content.

This change uses mime_content_type() and finfo_*() functions (if these
are installed) to detect the Content-Type.

When uploading a resource to GCS storage the Content-Type is explicitly
defined in metadata options.

```
'metadata' => [
    'contentType' => $resource->getMediaType()
]
```

However `getMediaType()` is always returning the fallback value
`application/octet-stream` as it's logic is based on using the filename
to determine the Content-Type. At this point the filename consists only
of a sha1 or a random value.

PHP's fileinfo extension has functions to detect a Content-Type based on
file content.

This change uses `mime_content_type()` and `finfo_*()` functions (if these
are installed) to detect the Content-Type.
@robertlemke robertlemke added this to In progress in Open Source Packages via automation Jan 31, 2020
Copy link
Member

@kdambekalns kdambekalns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me… I wonder about two things, though:

  • What is the connection to the gcs:updatresourcemetadata command? That reads the media type from the DB. So…
  • Is there no way to re-use that data , as it's obviously available in the system also during upload/import somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Open Source Packages
  
In progress
Development

Successfully merging this pull request may close these issues.

None yet

2 participants