NetCore is occasionally useful: NetCore project adds MIME

1. Introduction


1. The system provides us with the processing methods of some file types by default.

2. The file types that the system does not provide us with processing cannot be used, for example: apk

3. Here, you need to add MIME yourself to access

4. The following is an example of adding apk access

 

2. When MIME is not added


1. Put an apk file in the static directory

2. Enable UseStaticFiles (see Enabling Static Files in the Basics)

3. Access this file through http, and the result cannot be accessed

 

 

 

 

            app.UseStaticFiles();

 

 

 

 

 

3. After adding MIME


1. Add MIME code to Startup. Note that UseStaticFiles replaces the original one instead of adding one.

2. Revisit and download normally

 

            //添加MIME
            var provider = new FileExtensionContentTypeProvider();
            provider.Mappings[".apk"] = "application/vnd.android.package-archive";
            app.UseStaticFiles(new StaticFileOptions
            {
                ContentTypeProvider = provider
            });

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325804019&siteId=291194637