欢迎光临,了解微信小程序开发,就上易用通!

小程序开发填坑《十一》uploadFile脱坑IIS服务器无法上传大于50K的图片

发布:2018-01-25 11:43浏览: 来源:网络 作者:tianshu

40K一下的图片上传到服务器OK , 超过40K接口直接返回413的错误,请求实数据过大
服务器是IIS7.5: 已经修改了web_config/最大请求数据的值/也修改了maxRequestLength 但还是报错

解决办法:
打开IIS配置文件进入: C:\Windows\System32\inetsrv\config\schema\IIS_schema 找到name="uploadReadAheadSize" 注意看它的value值大概就是48xxx多少的换算成KB刚好和限制图片上传的大小近似修改完重启IIS即可 . 如果没有修改权限自行百度搜索教程 . 如果C盘下找不到此目录请自行换成自己的服务器配置目录

PS: 开发者工具中和苹果可以正常上传图片 , 但是安卓无法上传图片会报 uploadFile unkonwn 等待解决中!!!!!

也贴上修改其他配置项的代码把~~~
1. 修改IIS的applicationhost.config
打开 %windir%\system32\inetsrv\config\applicationhost.config
找到: <requestFiltering>节点,
这个节点默认没有 <requestLimits maxAllowedContentLength="上传大小的值(单位:byte)" /> 元素,IIS 7和IIS 7.5上测试过  最大值只能是<requestLimits maxAllowedContentLength="4294967295" />  <4GB,
为这个节点新增如下事例元素:<requestLimits maxAllowedContentLength="2147483647" /> ,上传的大小将改为2G
注意: %windir%\system32\inetsrv\config\applicationhost.config 文件一定不要用其他机器的文件替换,否则IIS将无法启动
此文件记录了,当前IIS中所有Site , App pool的信息,还有一些与机器相关的配置。

2. 修改web.config
<system.web>
  <httpRuntime executionTimeout="36000" maxRequestLength="2097151"/>
  <!--maxRequestLength:上传的大小,单位K   ,executionTimeout:设置超时时间,单位:秒。(默认是90秒) -->
</system.web>

注意:这个maxRequestLength最大值只能是2097151K,设置大于这个值将会出现如下错误:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The value for the property 'maxRequestLength' is not valid. The error is: The value must be inside the range 0-2097151.
Source Error:
<httpHandlers />
<customErrors mode="RemoteOnly" />
<httpRuntime executionTimeout="36000" maxRequestLength="4194304" />
<authentication mode="Windows" />
<identity impersonate="true" />

3.  web.config下如果有如下节点(此节点是为IIS 7设计的) ,则修改
<requestLimits maxAllowedContentLength="2147483647" />
单位与applicationhost.config中的<requestLimits maxAllowedContentLength="2147483647" />一致,它的最大值也只能为4294967295
<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483647" />
    </requestFiltering>
  </security>
</system.webServer>
 




免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。