将图像上传到服务器并在UITextView上显示其名称

时间:2016-08-10 15:27:17

标签: ios objective-c

有类似的问题,并有一些非常好的答案。因为我是iOS新手,所以我很难理解语法和逻辑。我有一个文本字段和一个用于上传图像的按钮。我需要在该文本字段中显示所选图像的名称。

上传图片的方法:

- (IBAction)btn_uploadPic:(id)sender {
    _picker = [[UIImagePickerController alloc] init];
    _picker.delegate = self;
    _picker.allowsEditing = YES;
    _picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:_picker animated:YES completion:NULL];
}

我的另一种方法是正确地在服务器上发布数据。我只需要添加图像上传到它。这是代码:

- (IBAction)btn_ideaSubmit:(id)sender {
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://mantis.vu.edu.pk/fundme/public/api/v1/createIdea"]];
    [request setHTTPMethod:@"POST"];
    NSString *postIdea =[NSString stringWithFormat:@"&idea_info=%@&idea_location=%@&idea_description=%@&idea_title=%@&selection=%@", _text_ideaInfo.text , _txt_ideaLocation.text , _txt_ideaDescription.text, _txt_idea.text, _txt_ideaCommunity.text];
    NSLog(@"the data Details is =%@", postIdea);
    NSData *data1 = [postIdea dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data1];
    NSError *err;
    NSURLResponse *response;
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
    NSString *resSrt = [[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding];
    NSLog(@"got response==%@", resSrt);
    if(resSrt)
    {
        NSLog(@"Data Posted Successfully");
    }   else
        {
            NSLog(@"failed to connect");
        }
}

在这方面的任何帮助将不胜感激。

0 个答案:

没有答案