Giter Site home page Giter Site logo

Comments (9)

4n1qz5skwv avatar 4n1qz5skwv commented on September 1, 2024 1

EDITED

return send_file(abspath, mimetype=mimetype)

return send_file(abspath)

https://github.com/pallets/flask/blob/7a73171edc3bcffef96ef6367977ab3ae9af9350/src/flask/helpers.py#L499

def send_file(..., as_attachment: bool = False)

I think adding this one argument as_attachment=True (TRUE) should solve this.

@general03

from flask-autoindex.

Anamura avatar Anamura commented on September 1, 2024 1

Hello! any news about this issue? if there any workaround will be appreciated

from flask-autoindex.

general03 avatar general03 commented on September 1, 2024

Hello,

I can't reproduce issue, in my computer I download files successfully.

You can configure your browser to force download file

from flask-autoindex.

4n1qz5skwv avatar 4n1qz5skwv commented on September 1, 2024

Here is the full code if you want to test it. Added some attachments.

import pathlib

from flask import Blueprint, Flask, send_file
from flask_autoindex import AutoIndexBlueprint

app = Flask(__name__)

foo_dir = pathlib.Path(r'C:\foo')

bp_ai = Blueprint('foo', __name__, static_folder='./static', template_folder='templates')
AutoIndexBlueprint(bp_ai, browse_root=f'{foo_dir.absolute()}', template_context=dict(x='y'))

app.register_blueprint(bp_ai, url_prefix='/ai')

sample_mp4_file_path = foo_dir / 'sample-mp4-file.mp4'


@app.route("/browser_ok_mp4_as_attachment_true")
def x():
    return send_file(f'{sample_mp4_file_path.absolute()}', as_attachment=True)


@app.route("/browser_ok_mp4_as_attachment_false")
def y():
    return send_file(f'{sample_mp4_file_path.absolute()}', as_attachment=False)


if __name__ == '__main__':
    app.run()

AI_04

AI_01

AI_02

AI_03

Test video is from here
As you can see its not browser issue. Browser will download file instead of opening if provided as_attachment=True in send_file. I found no way to provide this parameter in AutoIndex.

from flask-autoindex.

general03 avatar general03 commented on September 1, 2024

The as_attachment=True parameter allow to add Content-Disposition header to attachment so to download file as fai can do.

I think your issue title do not reflect that you want !

Your browser treat the header to do something : https://stackoverflow.com/a/1395173/2641416

from flask-autoindex.

4n1qz5skwv avatar 4n1qz5skwv commented on September 1, 2024

Oh... I See. Thanks.

Instead of opening a new issue or editing the title, I am just requesting here the feature request.
Please add an option to pass as_attachment=True parameter or something similar to AutoIndex, for adding Content-Disposition header to attachment.

Ex. During init, AutoIndexBlueprint(..., as_attachment=True) or,
Or, in config, AUTOINDEX_AS_ATTACHMENT = True

from flask-autoindex.

general03 avatar general03 commented on September 1, 2024

Your request is to configure globally the path to download all files inside ?

from flask-autoindex.

4n1qz5skwv avatar 4n1qz5skwv commented on September 1, 2024

Your request is to configure globally the path to download all files inside ?

Sorry, I don't understand the part "download all files inside".


Current Situation:
-> Clicking on a file, it load directly inside the browser.

Wanted Situation:
-> Clicking on a file, ask me save or download it.

How:
Enable Attachment mode by taking advantage of "as_attachment" parameter of send_file function. Which will add Content-Disposition header to attachment in file.

Request:
Please Give us an option to "Enable Attachment mode".


So, request is to configure globally the path to add Content-Disposition header to attachment for all file inside ?

from flask-autoindex.

rafaelsupport avatar rafaelsupport commented on September 1, 2024

hey guys
i have the same issue
i'm using this example: #16 (comment)
so
how can i disable this web preview and force download using this way as example?

from flask-autoindex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.