Nginx İle Force Download

January 20, 2020

Browserlar akıllandıkça, farklı dosya uzantıları için default aksiyonu değişiyor. Eskiden mp4 tipindeki bir uzantı gördüğü zaman default olarak indirmeye çalışırdı. Şimdilerde ise varsayılan olarak oynatmayı deniyor. Keza pdf için de aynı şey geçerli.

Statik dosyalara content-disposition header ı eklemek ne sürebilir? Ben de sizin gibi 5 dakika alacağını düşünmüştüm ancak yarım saat nginx dokumantasyonu okuduktan sonra fikrim değişti.

Aşağıdaki nginx konfigurasyonu bir subdirectory içindeki dosyaları listeliyor ve seçtiğiniz dosyalar mp4 veya pdf ise Content-Disposition header ı ekliyor.

Nginx Konfigurasyonu

1
2
3
4
5
6
7
8
location /bindaddress {

    # force it to download
    if ($request_filename ~ "^.*/(.+\.(mp4|pdf))$"){
        set $fname $1;
        add_header Content-Disposition 'attachment; filename="$fname"';
    }
}

hidden

AI: Where in the Loop Should Humans Go?

This is a re-publishing of a blog post I originally wrote for work, but wanted on my own blog as well.AI is everywhere, and its impressive claims are leading to rapid adoption. At this stage, I’d qualify it as charismatic technology—someth…

via Ferd.ca

More Good Programming Quotes, Part 6

Here are more good programming quotes I have found since my last post. Programming “Configuration is coding in a poorly designed programming language without tests, version control, or documentation.”Gregor Hohpe “It’s the developers misunderstanding, not…

via Henrik Warne's blog

HOWTO: Change your behavior

In theory, behavior change should be easy. At first glance, it seems like you control your behavior. So, if you desire different behavior, why doesn’t your behavior change as instantly as your desire to change it? In short, lasting change of habitual behavio…

via Matt Might's blog