Request failed: request too large (413)

服務(wù)器請(qǐng)求限制:

iis默認(rèn)只有200k

跟后臺(tái)反應(yīng)一下。iis默認(rèn)200K限制。ngnix默認(rèn)1M,apache默認(rèn)2M。

圖片壓縮:(寫了一個(gè)分類方法)

@implementation UIImage (Compress)

/*

*? 壓縮圖片至目標(biāo)尺寸

*

*? @param targetWidth 圖片最終尺寸的寬

*

*? @return 返回按照源圖片的寬、高比例壓縮至目標(biāo)寬、高的圖片

*/

-(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;

}

圖片轉(zhuǎn)二進(jìn)制壓縮:(注意UIImageJPEGRepresentation壓縮是有限度的,當(dāng)圖片比較大時(shí),最低壓縮到200k級(jí)別,此后無(wú)論壓縮值設(shè)置多小都不能再進(jìn)步壓縮)

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

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

object.data = UIImageJPEGRepresentation(icon,0.8);//0.8為壓縮值

一般上傳多張圖片,如果圖片張數(shù)比較少,請(qǐng)求一次接口,將一組圖片傳給服務(wù)器。如果圖片張數(shù)比較多,用遞歸來(lái)多次請(qǐng)求接口,通過(guò)每次請(qǐng)求的返回參數(shù)(如上傳的圖片名),來(lái)判斷該圖片是否上傳成功及是否所有圖片上傳完成。

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)}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容