37

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

John
  • 373
  • 1
  • 3
  • 4

7 Answers7

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
TimLau
  • 631
  • 1
  • 5
  • 3
29

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

application/vnd.android.package-archive
Jenny D
  • 27,358
  • 21
  • 74
  • 110
phoebus
  • 8,370
  • 1
  • 31
  • 29
12

Add this to the web.config:

<system.webServer>
   <staticContent>
     <mimeMap fileExtension="apk" mimeType="application/vnd.android.package-archive" />
   </staticContent>
<system.webServer>
Igor Gorjanc
  • 221
  • 2
  • 4
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; }
    }
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

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.

0

Extension : .apk

Type MIME : application/octet-stream

Zied R.
  • 101
  • 2