swfupload

07 09,2014

swfupload上传失败返回RESIZE_ERROR

上传用的是swfupload插件,今天有几张照片死活传不上去,调试发现返回的errorCode为-300。

找到-300在SWFUpload.UPLOAD_ERROR中的RESIZE,Ps:很奇怪,网上很少看到有-300的错误说明,倒是有ERROR_RESIZE这个变量

RESIZE_ERROR - 当调整图像大小时出现了某错误啊

看到这个提示一头雾水,图片本身是没问题的。用PHP 的GD库是可以裁剪的。

后来将message信息打印出来发现如下:Error generating resized image. Resizing: Error #2015

google 搜索发现这个是flash player的问题:

In AIR 1.5 and Flash Player 10, the maximum size for 
a BitmapData object is 8,191 pixels in width or height, 
and the total number of pixels cannot exceed 16,777,215 pixels. 
(So, if a BitmapData object is 8,191 pixels wide, 
it can only be 2,048 pixels high.) 

In Flash Player 9 and earlier and AIR 1.1 and earlier, 
the limitation is 2,880 pixels in height and 2,880 in width.
Starting with AIR 3 and Flash player 11, 
the size limits for a BitmapData object have been removed. 
The maximum size of a bitmap is now dependent on the operating system.

如上说明,图片的高宽不能超过8191px,然后总的像素值不能超过16777215px,总像素值计算为:height px * width px。

查看了下上传图片的px为:高度:5184px, 宽度:3456px。总像素值:5184*3456 = 17915904,这个值大于了flash player的限制了。

用ps打开图片修改下图片大小为:高度:4984px,宽度:3323px,总像素值:4984*3323 = 16561832,刚刚好小于flash player的限制,上传,ok,没问题了。果然是这个限制的问题!

PS:上面说flash player 11版本已经移除了这个限制,改为根据系统进行限制,但是不知道系统限制是如何计算的。反正我升级为flash player14上传也提示这个错误。

2014-11-17日更新

推荐一个由百度开源的上传插件webuploader,可以解决此问题。
官方地址: http://fex.baidu.com/webuploader/
其他有点可以查看官网介绍。