获取文件的 MIMEType

能够获取文件的 MIMEType.

{

    上传文件的时候,需要告诉服务器文件类型(Content-Type),这时,需要获取文件的 MIMEType.

    

    获取文件的 MIMEType 方法:加载文件时,通过 response 获得

    {

        NSURLRequest *request = [NSURLRequest requestWithURL:url];

        

        NSURLResponse *response = nil;

        

        [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:NULL];

        

        NSLog(@"%@",response.MIMEType);

        

    }

    response.MIMEType 即为 Content-Type 的类型.

    

    如果不想告诉服务器具体的文件类型,可以使用这个 Content-Type : application/octet-stream(8进制流)

    

    常见的 Content-Type 类型:

    {

        - 大类型/小类型

        - text/plain

        - image/jpg

        - image/png

        - image/gif

        - text/html

        - application/json

    }

    

}

posted @ 2015-09-15 09:32  熊虎成  阅读(532)  评论(0编辑  收藏  举报