ASI上传图片到后台

来源:互联网 发布:阿里云 上海机房 编辑:程序博客网 时间:2024/05/28 15:31

#pragma mark - ASI上传图片到服务器

//==================================================================

-(void)uploadImgToServer:(UIImage*)image{

    

    // Do something usefull in here instead of sleeping ...

    NSURL *URL = [NSURLURLWithString:@"XXX/consultation/uploadShowPic.json"];

    ASIFormDataRequest *Request = [ASIFormDataRequestrequestWithURL:URL];

    [RequestsetRequestMethod:@"POST"];

    [Request addRequestHeader:@"Content-Type"value:@"multipart/form-data"];

    [Request setTimeOutSeconds:60];

    

//    UIImage *img2 = [UIImage imageNamed:@"haha.jpg"];

//    NSData *data2=UIImageJPEGRepresentation(img2, 1.0);

    

//    UIImage *img = [UIImage imageNamed:@"shop_pic.png"];

//    NSData *data = UIImagePNGRepresentation(img);//获取图片数据

    

    NSData *data2 =UIImageJPEGRepresentation(image, 1.0);

    

//    NSString *str = @"{\"pid\":\"\", \"itemId\":\"118\"}";       post的body传参数

    NSString *str = [NSStringstringWithFormat:@"{\"pid\":\"%@\",\"itemId\":\"%@\"}",_conIdStr,self.shareModel.itemId];

    [RequestsetPostValue:str forKey:@"resinfo"];

    [Request setData:data2withFileName:@"haha.jpg"andContentType:@"jpg"forKey:@"multipartFile"]; //上传图片二进制

    

    [RequestsetDelegate:self];

    [Request startAsynchronous];

}



//=============================第二种方法=====================================



0 0