35

I would like to know how to configure IIS 7.0 to allow the download of APK files?

I found an article which tells me to add a new MIME type:

File Name Extension: .apk

MIME Type: application/vnd.android.package-archive

Because In IIS there needs to be a MIME type added to allow IIS to support the .APK file type.

Is this all that is needed?

Thanks for any replies

7 Answers 7

28

Generally, adding a new MIME type should be all that's required:

application/vnd.android.package-archive
2
  • 3
    Generally, true. Annoyingly, type wasn't included in your "answer". Oct 20, 2015 at 21:40
  • how is this the accepted answer? May 8, 2017 at 18:24
53
  1. Open the Internet Information Service (IIS) Manager -> Properties
  2. Click MIME types
  3. New -> type Extension ".apk" and MIME type "application/vnd.android.package-archive"
  4. Click Ok and Apply
2
  • 2
    andrOId, not andrIOd
    – Pierre
    Feb 28, 2015 at 18:06
  • Pierre, Thx correct me and updated
    – TimLau
    Apr 1, 2015 at 7:36
10

Add this to the web.config:

<system.webServer>
   <staticContent>
     <mimeMap fileExtension="apk" mimeType="application/vnd.android.package-archive" />
   </staticContent>
<system.webServer>
0

Using the method above doesn't require the MIME type to be set in IIS, just add the static content in your web.config file, as mentioned by Igor

2
  • <div> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/android-debug-unaligned.apk">Download</asp:HyperLink> </div> Jan 19, 2017 at 17:50
  • web.config = <staticContent> <mimeMap fileExtension="apk" mimeType="application/vnd.android.package-archive" /> </staticContent> </system.webServer> Jan 19, 2017 at 17:51
0

a better option is to use the MIME of a Zip file, since an apk is actually a zip file and is IIS knows it.

for me worked just fine with a server with Windows 10 Anniversary.

1
  • Is there some config (or pointers) you could share? Mar 4, 2017 at 12:43
0

Extension : .apk

Type MIME : application/octet-stream

0

For ASP.NET Core applications, IIS changes won't work.

In your Startup.cs file's Configure method, make the following changes:

app.UseStaticFiles(new StaticFileOptions()
            {
                ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string>
  {
    { ".apk","application/vnd.android.package-archive"}
  })
            });

A better option is to read extension/ mime type pairs from config and inject it into the Config method like this so that extensions can be managed from configuration:

appsettings.json:

"StaticFilesConfig": {
    "AllowedExtensions": {
      ".apk": "application/vnd.android.package-archive",
      ".ext": "application/ext-example-mimetype" // example
    } 
  }

Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
....
services.Configure<StaticFilesConfig>(Configuration.GetSection("StaticFilesConfig"));
....
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env
 , ILoggerFactory loggerFactory, IOptions<StaticFilesConfig> staticFilesConfig)
{
...
if (staticFilesConfig != null)
            {
                SetStaticFileOptions(app, staticFilesConfig);
            }
...
}

private void SetStaticFileOptions(IApplicationBuilder app
, IOptions<StaticFilesConfig> staticFilesOptions)
        {
            var mapping = staticFilesOptions.Value.AllowedExtensions;
            if (mapping != null && mapping.Any())
            {
                var provider = 
  new FileExtensionContentTypeProvider(staticFilesOptions.Value.AllowedExtensions);
                app.UseStaticFiles(new StaticFileOptions
                {
                    ContentTypeProvider = provider
                });
            }
        }
}

StaticFilesConfig.cs:

public class StaticFilesConfig
    {
        public IDictionary<string, string> AllowedExtensions { get; set; }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.