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

[gcloud] Add support for MIME type #320

Merged
merged 1 commit into from
Jul 2, 2017
Merged

[gcloud] Add support for MIME type #320

merged 1 commit into from
Jul 2, 2017

Conversation

Sgiath
Copy link
Contributor

@Sgiath Sgiath commented May 17, 2017

Resolves #303 Issue

@codecov-io
Copy link

codecov-io commented May 17, 2017

Codecov Report

Merging #320 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #320      +/-   ##
==========================================
+ Coverage   75.58%   75.61%   +0.03%     
==========================================
  Files          11       11              
  Lines        1544     1546       +2     
==========================================
+ Hits         1167     1169       +2     
  Misses        377      377
Impacted Files Coverage Δ
storages/backends/gcloud.py 95.7% <100%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b5027d2...d96107d. Read the comment docs.

@Sgiath
Copy link
Contributor Author

Sgiath commented May 17, 2017

I also checked that this is working on my site.

@svengt
Copy link

svengt commented May 26, 2017

@Sgiath
Copy link
Contributor Author

Sgiath commented Jun 5, 2017

@svengt I did not know about this function. Thanks for it! I fixed it now.

@Sgiath
Copy link
Contributor Author

Sgiath commented Jun 27, 2017

@jschneier or @scjody can you please Merge it or tell me what should be fixed? Thanks

@jleclanche
Copy link
Contributor

Looks fine with me but I don't know gcloud well enough to decide on it.

It needs rebasing, by the way. Please squash your commits together and rebase on master.

Copy link
Contributor

@scjody scjody left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Can you add an option to override the detected MIME type and fix the minor style issues?

After that plus rebasing and squashing I'd be happy to merge this!

@@ -20,6 +21,7 @@
class GoogleCloudFile(File):
def __init__(self, name, mode, storage):
self.name = name
self.mime_type = mimetypes.guess_type(name)[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Since guess_type isn't 100% reliable, I think we need to allow the user to override the type here if needed. Can you add that?

Copy link
Contributor Author

@Sgiath Sgiath Jun 27, 2017

Choose a reason for hiding this comment

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

When the user should override it? Globally at the Django settings (set the desired MIME type for specific file extension)? Something like:

GS_MIME_TYPE = {
    '.css': 'text/css',
    '.mp4': 'video/mp4',
}

I didn't add it because MIME types are not THAT important. They can be edited manually in Google Cloud Console if really needed and almost everything should work also without them. So I didn't want to add complexity with another settings option.
But if you thinks it is needed I can definitely add this to the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now that I've looked more closely, I don't see a good place to add this. Django's storage API doesn't have any support for MIME types as far as I can tell, so we're well within our rights to set whatever we want when saving a file to the storage provider.

@@ -153,7 +155,7 @@ def _save(self, name, content):
content.name = cleaned_name
encoded_name = self._encode_name(name)
file = GoogleCloudFile(encoded_name, 'rw', self)
file.blob.upload_from_file(content, size=content.size)
file.blob.upload_from_file(content, size=content.size, content_type=file.mime_type)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to wrap lines at 79 columns (although the Django Coding Style allows up to 119 if needed for readability). Here you can put content_type=... on the next line without hurting readability, so please do.

@@ -91,7 +92,7 @@ def test_open_write(self, MockBlob):
# File data is not actually written until close(), so do that.
f.close()

MockBlob().upload_from_file.assert_called_with(tmpfile)
MockBlob().upload_from_file.assert_called_with(tmpfile, content_type=mimetypes.guess_type(self.filename)[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

Here it would be preferable to put content_type on the next line. This will still make the line longer than 79 characters but that's OK.

Copy link
Contributor

@scjody scjody left a comment

Choose a reason for hiding this comment

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

Thanks for the style changes and the discussion about overrides. I'm OK with merging this. @jschneier is this OK with you?

@@ -20,6 +21,7 @@
class GoogleCloudFile(File):
def __init__(self, name, mode, storage):
self.name = name
self.mime_type = mimetypes.guess_type(name)[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that I've looked more closely, I don't see a good place to add this. Django's storage API doesn't have any support for MIME types as far as I can tell, so we're well within our rights to set whatever we want when saving a file to the storage provider.

@jschneier
Copy link
Owner

jschneier commented Jun 28, 2017 via email

@Sgiath
Copy link
Contributor Author

Sgiath commented Jul 1, 2017

OK squashed and rebased. You can merge it.

nitely pushed a commit to satellogic/django-storages that referenced this pull request Jul 30, 2018
nitely pushed a commit to satellogic/django-storages that referenced this pull request Jul 30, 2018
nitely pushed a commit to satellogic/django-storages that referenced this pull request Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants