开发者社区> 问答> 正文

请问ios上传图片jav后台如何接收 ?

我java后台是用spring、struts2

展开
收起
爵霸 2016-03-13 11:30:12 2615 0
1 条回答
写回答
取消 提交回答
  • 苹果客户端上传图片 java接收

    ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlstr]];
     //分界线的标识符
     NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
     //分界线 --AaB03x
     NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
     //结束符 AaB03x--
     NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
     //声明结束符:--AaB03x--
     NSString *end=[[NSString alloc]initWithFormat:@"rn%@",endMPboundary];
     //声明myRequestData,用来放入http body
     NSMutableData *myRequestData=[NSMutableData data];
     NSMutableString *body=[[NSMutableString alloc]init];
     //将body字符串转化为UTF8格式的二进制
     [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
     //将image的data加入
     UIImage *image = [UIImage imageNamed:@"1212312.png"];
     NSData * imageData = UIImagePNGRepresentation(image);
     [request setData:imageData withFileName:@"1122.png" andContentType:@"image/png" forKey:@"photo"];
     [request setPostValue:string forKey:@"note"];//额外的文字参数
     //加入结束符--AaB03x--
     [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
     NSLog(@"myRequestData = %@",myRequestData);
     //设置HTTPHeader中Content-Type的值
     NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
     [request addRequestHeader:@"Content-Type" value:content];
     [request addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d", [myRequestData length]]];
     [request setPostBody:myRequestData];
     [request setRequestMethod:@"POST"];
     [request startAsynchronous];
    2019-07-17 19:02:18
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载