日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > 綜合技術(shù) > 上傳文件至服務(wù)器

上傳文件至服務(wù)器

來源:程序員人生   發(fā)布時間:2014-12-13 08:47:52 閱讀次數(shù):3234次
//上傳圖片 -(void)showActionSheet { //在這里呼出下方菜單按鈕項 myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles: @"打開照相機(jī)", @"從手機(jī)相冊獲得",nil]; [myActionSheet showInView:self.view]; [myActionSheet release]; } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { //呼出的菜單按鈕點(diǎn)擊后的響應(yīng) if (buttonIndex == myActionSheet.cancelButtonIndex) { NSLog(@"取消"); } switch (buttonIndex) { case 0: //打開照相機(jī)拍照 [self takePhoto]; break; case 1: //打開本地相冊 [self LocalPhoto]; break; } } //開始拍照 -(void)takePhoto { UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; //設(shè)置拍照后的圖片可被編輯 picker.allowsEditing = YES; picker.sourceType = sourceType; [picker release]; [self presentViewController:picker animated:YES completion:nil]; }else { NSLog(@"摹擬其中沒法打開照相機(jī),請在真機(jī)中使用"); } } //打開本地相冊 -(void)LocalPhoto { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self; //設(shè)置選擇后的圖片可被編輯 picker.allowsEditing = YES; [self presentViewController:picker animated:YES completion:nil]; [picker release]; } //當(dāng)選擇1張圖片落后入這里 -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSString *type = [info objectForKey:UIImagePickerControllerMediaType]; //當(dāng)選擇的類型是圖片 if ([type isEqualToString:@"public.image"]) { NSLog(@"您選擇了該圖片"); //先把圖片轉(zhuǎn)成NSData UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; NSData *data; if (UIImagePNGRepresentation(image) == nil) { data = UIImageJPEGRepresentation(image, 1.0); } else { data = UIImagePNGRepresentation(image); } //圖片保存的路徑 //這里將圖片放在沙盒的documents文件夾中 NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; //文件管理器 NSFileManager *fileManager = [NSFileManager defaultManager]; //把剛剛圖片轉(zhuǎn)換的data對象拷貝至沙盒中 并保存為image.png [fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil]; [fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:data attributes:nil]; //得到選擇后沙盒中圖片的完全路徑 filePath = [[NSString alloc]initWithFormat:@"%@%@",DocumentsPath, @"/image.png"]; //關(guān)閉相冊界面 [picker dismissViewControllerAnimated:YES completion:nil]; [self imageUpload:image]; } } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { NSLog(@"您取消了選擇圖片"); [picker dismissViewControllerAnimated:YES completion:nil]; } //上傳圖片到服務(wù)器方法,采取了ASIFormDataRequest方法 - (void) imageUpload:(UIImage *) image{ UIImage *im = [UIImage imageWithContentsOfFile:filePath];//通過path圖片路徑獲得圖片 NSData *data = UIImagePNGRepresentation(im);//獲得圖片數(shù)據(jù) /* ios中獲得圖片的方法有兩種,1種是UIImageJPEGRepresentation ,1種是UIImagePNGRepresentation 前者獲得到圖片的數(shù)據(jù)量要比后者的小很多。。 */ //服務(wù)器地址 NSURL *url = [NSURL URLWithString:@"這里寫入你的服務(wù)器上傳地址"]; aRequest = [[ASIFormDataRequest alloc] initWithURL:url]; [aRequest setDelegate:self];//代理 [aRequest setRequestMethod:@"POST"]; //這個參數(shù)還不是很清楚 [aRequest addData:data withFileName:@"test.png" andContentType:@"image/png" forKey:@"file"]; [aRequest addRequestHeader:@"Content-Type" value:@"multipart/form-data"];//這里的value值 需與服務(wù)器端 1致 [aRequest startAsynchronous];//開始。異步 [aRequest setDidFinishSelector:@selector(headPortraitSuccess)];//當(dāng)做功后會自動觸發(fā) headPortraitSuccess 方法 [aRequest setDidFailSelector:@selector(headPortraitFail)];//如果失敗會 自動觸發(fā) headPortraitFail 方法 } -(void)headPortraitSuccess{ NSData * myResponseData = [aRequest responseData]; //獲得數(shù)據(jù) : 調(diào)試的時候,在這里, myResponseData的值1直是nil,不知道為何? //將接收的數(shù)據(jù)轉(zhuǎn)換成NSString類型并打印出來 NSString *result = [[NSString alloc] initWithData:myResponseData encoding:NSUTF8StringEncoding]; NSLog(@"result------------>%@", result); NSDictionary *data = [result objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode]; NSArray *imgArray = [data objectForKey:@"data"]; NSString *imgpath=@"http://twww.51qed.com"; if ([imgArray count]) { NSDictionary *imgInfo = [imgArray objectAtIndex:0]; imgpath = [imgpath stringByAppendingString:[imgInfo objectForKey:@"img"]]; NSLog(@"imgpath------------>%@", imgpath); } //設(shè)置H5圖片更新,ios調(diào)用JS代碼 [webview stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"setNewImg('%@');",imgpath]]; NSLog(@"上傳成功!"); [aRequest release]; } -(void)headPortraitFail{ NSLog(@"上傳失??!"); } //開始request要求 - (void)requestStarted:(ASIHTTPRequest *)request{ NSLog(@"開始要求!"); } @end
需導(dǎo)入
<pre name="code" class="objc">#import "ASIHTTPRequest.h" #import "ASIFormDataRequest.h" #import "JSONKit.h"

這3個頭文件


     
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 欧美精品乱码久久久久久 | 日韩免费视频一区二区 | 午夜免费视频 | 久久精品国产精品亚洲 | 久久久精品一区二区三区 | 国产在线播放一区二区 | 国产一区二区三区日韩 | 91精品国产九九九久久久亚洲 | 久久草av| 欧美福利一区二区 | 麻豆免费视频 | 丁香六月色婷婷 | 欧美色图亚洲自拍 | 国产成人精品在线 | 黄a视频| 久久成人免费 | 114一级毛片 | 午夜伦情电午夜伦情电影如如视频 | www.国产高清 | 亚洲自拍偷拍一区 | 粉嫩久久99精品久久久久久夜 | 国产成人精品一区二 | 婷婷精品国产一区二区三区日韩 | 黄色大片电影 | 欧美亚洲国产一区二区三区 | 精品国产一区二区三区成人影院 | 久久亚洲成人 | 欧美jizz欧美性大全 | 一级黄色毛片子 | 日韩不卡一区二区 | 中文在线一区二区 | 免费黄网站 | 久久精品视频免费观看 | 色婷婷成人做爰视频免费 | 一区二区亚洲视频 | 国产精品免费一区二区 | 一区二区三区四区在线观看视频 | 色婷婷5月 | 日韩欧美高清 | 成年人免费看 | 久久国产精品久久久 |