2016-07-26 7 views
0

私は現在、スクリーンショットといくつかのキー値を辞書でキャプチャするビデオ編集部分に取り組んでいます。最後に録音が終わると、私は辞書の配列を持っています。辞書の配列をサーバーにアップロードしてからダウンロードします。

私はこの辞書の配列をサーバーにアップロードし、後でその配列をダウンロードしたいと思います。

NSMutableArrayをバイトに変換してテキストファイルに書き込んだ後、テキストファイルをダウンロードしてNSMutableArrayに変換してみました。

その中の辞書にはキー値がありません。

この情報をサーバーにアップロードしてダウンロードする他の方法はありますか?

+0

コードを貼り付けることはできますか? –

+0

配列をNSDataに変換しないのはなぜですか?サーバー上に投稿し、ダウンロード後に簡単に解析できるようにデータをJSONに変換することができます。 –

答えて

0

あなたの情報と画像を分離する必要があります。 アップロードしてください。

あり例:

- (void)viewDidLoad { 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 

//------------------This part is for upload------------------ 
//Upload info 
UIImage* sourceImage = [UIImage imageNamed:@"source.png"]; 
UIImageView* imgV1 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; 
imgV1.backgroundColor = [UIColor redColor]; 
imgV1.image = sourceImage; 
[self.view addSubview:imgV1]; 

NSDictionary* uploadDic = [[NSDictionary alloc] initWithObjectsAndKeys: 
          @"source.png",@"testImage", 
          nil]; 
NSData* uploadData = [NSJSONSerialization dataWithJSONObject:uploadDic options:NSJSONWritingPrettyPrinted error:nil]; 
NSString* uploadString = [[NSString alloc] initWithData:uploadData encoding:NSUTF8StringEncoding]; 

//Upload image 
NSData* imageData = [NSData dataWithContentsOfFile:@"source.png"]; 
[self uploadInfoToURL:uploadString andImageData:imageData]; 
//----------------------------------------------------------- 

//------------------This part is for upload------------------ 
//Download info 
NSString *downLoadString = uploadString; 
NSData* downLoadData = [downLoadString dataUsingEncoding:NSUTF8StringEncoding]; 
NSDictionary *downLoadDic = [NSJSONSerialization JSONObjectWithData:downLoadData options:NSJSONReadingMutableContainers error:nil]; 
UIImageView* imgV2 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 250, 100, 100)]; 
imgV2.backgroundColor = [UIColor blueColor]; 
[self.view addSubview:imgV2]; 

//Download image 
NSString* downURL = [NSString stringWithFormat:@"http://youServer/%@",[downLoadDic objectForKey:@"testImage"]]; 
imgV2.image = [self getImageFromURL:downURL]; 
//----------------------------------------------------------- 
} 

-(UIImage *) getImageFromURL:(NSString *)fileURL { 
NSLog(@"Begin download"); 
UIImage * result; 
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]]; 
result = [UIImage imageWithData:data]; 
return result; 
} 

-(BOOL *) uploadInfoToURL:(NSString *)infoString andImageData:(NSData *)data { 
NSLog(@"Begin upload"); 
//Use http post to upload your image data to you server 
// if (nil == error) { 
//  return YES; 
// } 
return NO; 
} 

は、それはあなたを助けることができると思います。

+0

一度に何百もの画像が存在する可能性があります – Testiphone

関連する問題