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

Resource interpreted as Stylesheet but transferred with MIME type binary/octet-stream #88

Open
kubber opened this issue Jul 7, 2017 · 4 comments

Comments

@kubber
Copy link

kubber commented Jul 7, 2017

I used create_all to upload all static to S3, but browser show me message as above and css is not interpreted.

Looks like some content-type needs to be set
http://blog.viktorkelemen.com/2012/05/amazon-s3-and-resource-interpreted-as.html

@Fuyukai
Copy link
Collaborator

Fuyukai commented Jul 19, 2017

I believe this can be solved by setting FLASKS3_FORCE_MIMETYPE to True in your app's config.

@jwtrhs
Copy link

jwtrhs commented Jul 1, 2018

Been a while, but if anyone else comes across this issue I also had success using FLASKS3_FILEPATH_HEADERS to force the right content type in S3. E.g.:

app.config['FLASKS3_FILEPATH_HEADERS'] = {
    r'.css$': {
        'Content-Type': 'text/css',
    }
}

@yinhedot
Copy link

yinhedot commented Mar 7, 2021

use send_from_directory and setup mimetype:

from flask import send_from_directory

scriptPath = os.path.dirname(os.path.realpath(__file__))
os.chdir(scriptPath) 

template_folder = os.path.join(os.getcwd(),'templates')
static_folder = os.path.join(os.getcwd(),'static')
app = Flask(__name__, template_folder=template_folder,static_folder=static_folder)

@app.route('/css/<path:path>')
def send_css(path):
    return send_from_directory('css', path,mimetype='text/css')

@martinthomas
Copy link

Minor defect in documentation:
The example for FLASKS3_FILEPATH_HEADERS encloses the header list in quotes and makes it a string when it should be a dictionary as seen in the comment above.

Wrong (from docs):
{r'.txt$': {‘Texted-Up-By’: ‘Mister Foo’} }

Right:
{r'.txt$': {‘Texted-Up-By’: ‘Mister Foo’}}

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

No branches or pull requests

5 participants