Solved: The apk files was download as zip file on Android device
Problem
Problem
We put the apk files on the server, so the Android device can download the apk file with URL, we use nginx as the web server, but today we encounter a problem, when we download the apk file from android device, it was saved as zip file, on my first machine, it does not have problem, but after we moved to another server, the problem appears.
Solution to the problem
I searched the internet, and find the solution which is to add the following line to the /etc/nginx/mime.types
application/vnd.android.package-archive apk;
After added this line, and restarted the nginx server, the apk file can be downloaded successfully.
Updated
After I added the setting and restart the nginx server, it works. But when I try to download another file, the file still being saved as zip file, I want to solve the problem.
I try to add the following settings:location ~* \.(apk)$ {
default_type application/vnd.android.package-archive;
add_header Content-Type application/vnd.android.package-archive;
add_header Content-Disposition "attachment";
But the problem still exists, then I try to add the attachment name, so the setting is like below:location ~* \.(apk)$ {
default_type application/vnd.android.package-archive;
add_header Content-Type application/vnd.android.package-archive;
add_header Content-Disposition attachment;filename="test.apk";
After this setting, the file was downloaded as test.apk
, so I want to replace the file name with the name on the URL, but I remove the filename again, but keep the single quote for the attachment like below:location ~* \.(apk)$ {
default_type application/vnd.android.package-archive;
add_header Content-Type application/vnd.android.package-archive;
add_header Content-Disposition 'attachment';
And the file was downloaded as apk
file.
Conclusion
I don’t know whether the problem is solved or not, I still need some time to test it. So for me, to solve the problem I do the following two steps:
- Added mime type
- Added attachment header