Getting ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION in django
Question:
I am getting ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION in Chrome browser with the following given code below in django.
redirect_path = 'some-url'
response = HttpResponseRedirect(redirect_path)
response['Content-Disposition'] = 'attachment; filename=file-from-+324#10,+4324.mp3'
return response
Things are working find in other browser.
Please let me know what I am doing wrong on this.
Answers:
The problem is that you have a comma in the filename. You should quote the header in the filename. I tested that the following view works in Chrome.
def my_view(request):
response = HttpResponse('hello')
response['Content-Disposition'] = 'attachment; filename="filename,with,commas.txt"'
return response
See this discussion on the Chrome help forum for more information.
Further to the answer from @Alasdair to remove the commas from the filename if it is generated dynamically, you can call .replace()
when constructing the filename in the response
object.
redirect_path = 'some-url'
response = HttpResponseRedirect(redirect_path)
response['Content-Disposition'] = 'attachment; filename=file-from-+324#10,+4324.mp3'
return response
becomes
redirect_path = 'some-url'
filename_to_return = "file-from-+324#10,+4324.mp3".replace(',', '_')
response = HttpResponseRedirect(redirect_path)
response['Content-Disposition'] = 'attachment; filename=%s' % filename_to_return
return response
You just have to replace the filename string with the dynamic variable that gets passed into the function.
I am getting ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION in Chrome browser with the following given code below in django.
redirect_path = 'some-url'
response = HttpResponseRedirect(redirect_path)
response['Content-Disposition'] = 'attachment; filename=file-from-+324#10,+4324.mp3'
return response
Things are working find in other browser.
Please let me know what I am doing wrong on this.
The problem is that you have a comma in the filename. You should quote the header in the filename. I tested that the following view works in Chrome.
def my_view(request):
response = HttpResponse('hello')
response['Content-Disposition'] = 'attachment; filename="filename,with,commas.txt"'
return response
See this discussion on the Chrome help forum for more information.
Further to the answer from @Alasdair to remove the commas from the filename if it is generated dynamically, you can call .replace()
when constructing the filename in the response
object.
redirect_path = 'some-url'
response = HttpResponseRedirect(redirect_path)
response['Content-Disposition'] = 'attachment; filename=file-from-+324#10,+4324.mp3'
return response
becomes
redirect_path = 'some-url'
filename_to_return = "file-from-+324#10,+4324.mp3".replace(',', '_')
response = HttpResponseRedirect(redirect_path)
response['Content-Disposition'] = 'attachment; filename=%s' % filename_to_return
return response
You just have to replace the filename string with the dynamic variable that gets passed into the function.