objective-c - iOS以流的形式上传图片
怪我咯
怪我咯 2017-06-06 09:52:38
0
1
790

公司这边上传图片,服务器端人员说是已图片流的方式上传图片,我尝试了如下几种方式都不行:

[manager POST:@"http://xxxxxxxx:8094/interface_normal/editorFile/uploadImages.do" parameters:nil constructingBodyWithBlock:^(id formData) { NSData* imageData = UIImageJPEGRepresentation(images[i], 0.5); [formData appendPartWithFileData:imageData name:@"file" fileName:@"tupian.png" mimeType:@"image/png"]; } success:^(NSURLSessionDataTask *task, id responseObject) { NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil]; } failure:^(NSURLSessionDataTask *task, NSError *error) { }];

还有如下的方式:

NSData *data = UIImageJPEGRepresentation(image, 0.5f); NSString *uploadUrl = [NSString stringWithFormat:@"%@editorFile/uploadImages.do", BASE_URL]; NSInputStream *imageStream = [[NSInputStream alloc] initWithData:data]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:uploadUrl]]; [request setHTTPMethod:@"POST"]; [request setValue:[NSString stringWithFormat:@"%ld", [data length]] forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; operation.inputStream = imageStream; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { completionBlock(responseObject, nil); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { completionBlock(operation.responseObject,error); }]; [operation start];

还是上传失败,请大神帮忙解答

安卓端上传时可以的,使用Charles抓包安卓上传图片的接口如下:

iOS这边抓包的结果如下,尝试过很过方式,服务器提示上传失败

另外服务器端告诉我,他是这样获取输入流的,但是他获取我的输入流是nil

InputStream is = request.getInputStream(); DataInputStream input = new DataInputStream(is); byte[] buf = new byte[2048]; byte[] tb = new byte[input.readInt()];
怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复 (1)
左手右手慢动作

应用程序/八位字节流

    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责声明 Sitemap
    PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!