ASI上傳圖片到後臺

#pragma mark - ASI上傳圖片到服務器

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

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

    

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

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

    ASIFormDataRequest *Request = [ASIFormDataRequest requestWithURL:URL];

    [Request setRequestMethod:@"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 = [NSString stringWithFormat:@"{\"pid\":\"%@\",\"itemId\":\"%@\"}",_conIdStr,self.shareModel.itemId];

    [Request setPostValue:str forKey:@"resinfo"];

    [Request setData:data2 withFileName:@"haha.jpg" andContentType:@"jpg" forKey:@"multipartFile"];  //上傳圖片二進制

    

    [Request setDelegate:self];

    [Request startAsynchronous];

}



//=============================第二種方法=====================================



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章