美文网首页
Request failed: request too larg

Request failed: request too larg

作者: 然亦伞 | 来源:发表于2016-11-29 18:21 被阅读2170次

    服务器请求限制:

    iis默认只有200k

    跟后台反应一下。iis默认200K限制。ngnix默认1M,apache默认2M。

    图片压缩:(写了一个分类方法)

    @implementation UIImage (Compress)

    /*

    *  压缩图片至目标尺寸

    *

    *  @param targetWidth 图片最终尺寸的宽

    *

    *  @return 返回按照源图片的宽、高比例压缩至目标宽、高的图片

    */

    -(UIImage *)compressImageToTargetWidth:(CGFloat)targetWidth{

    CGSize imageSize = self.size;

    CGFloat width = imageSize.width;

    CGFloat height = imageSize.height;

    CGFloat targetHeight = (targetWidth / width) * height;

    UIGraphicsBeginImageContext(CGSizeMake(targetWidth, targetHeight));

    [self drawInRect:CGRectMake(0, 0, targetWidth, targetHeight)];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newImage;

    }

    图片转二进制压缩:(注意UIImageJPEGRepresentation压缩是有限度的,当图片比较大时,最低压缩到200k级别,此后无论压缩值设置多小都不能再进步压缩)

    UIImage *icon = iconArr[i][@"icon"];

    NSString *name = iconArr[i][@"name"];

    object.data = UIImageJPEGRepresentation(icon,0.8);//0.8为压缩值

    一般上传多张图片,如果图片张数比较少,请求一次接口,将一组图片传给服务器。如果图片张数比较多,用递归来多次请求接口,通过每次请求的返回参数(如上传的图片名),来判断该图片是否上传成功及是否所有图片上传完成。

    Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: request too large (413)" UserInfo={com.alamofire.serialization.response.error.response={ URL: http://sssy.yssp.com:80/api/Own/editChengjiao } { status code: 413, headers {

    Connection = close;

    "Content-Length" = 199;

    "Content-Type" = "text/html";

    Date = "Tue, 29 Nov 2016 02:33:02 GMT";

    Server = "nginx/1.10.0";

    } }, NSErrorFailingURLKey=http://ss.ysscp.com:80/api/Own/editChengjiao, com.alamofire.serialization.response.error.data=<3c68746d 6c3e0d0a 3c686561 643e3c74 69746c65 3e343133 20526571 75657374 20456e74 69747920 546f6f20 4c617267 653c2f74 69746c65 3e3c2f68 6561643e 0d0a3c62 6f647920 6267636f 6c6f723d 22776869 7465223e 0d0a3c63 656e7465 723e3c68 313e3431 33205265 71756573 7420456e 74697479 20546f6f 204c6172 67653c2f 68313e3c 2f63656e 7465723e 0d0a3c68 723e3c63 656e7465 723e6e67 696e782f 312e3130 2e303c2f 63656e74 65723e0d 0a3c2f62 6f64793e 0d0a3c2f 68746d6c 3e0d0a>, NSLocalizedDescription=Request failed: request too large (413)}

    相关文章

      网友评论

          本文标题:Request failed: request too larg

          本文链接:https://www.haomeiwen.com/subject/urczpttx.html