0

iPhoneアプリ初心者です。

私が欲しいのは、サーバーに画像を保存することです。私が持っているのはボタンです。クリックすると、写真またはライブラリを尋ねられ、画像を選択します。

しかし、この画像をサーバーに保存する方法がわかりません。

#pragma mark - UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)theActionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        [self takePhotoCam];
    } else if (buttonIndex == 1) {
        [self choosePhotoFromLibrary];
    }
}


- (IBAction)takePhotoAction:(id)sender {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                      initWithTitle:nil
                                      delegate:self
                                      cancelButtonTitle:@"Cancel"
                                      destructiveButtonTitle:nil
                                      otherButtonTitles:@"Take Photo", @"Choose From Library", nil];

        [actionSheet showInView:self.view];
    } else {
        [self choosePhotoFromLibrary];
    }
}

- (void)takePhotoCam {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    [self.navigationController presentViewController:imagePicker animated:YES completion:nil];
}

- (void)choosePhotoFromLibrary {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    [self.navigationController presentViewController:imagePicker animated:YES completion:nil];
}
4

2 に答える 2

0

以下は私の問題を解決したリンクです。

サーバーに画像を保存する方法

これが誰かを助けることを願っています...

于 2013-03-07T09:07:38.377 に答える
0
- (void)uploadImageToServer:(NSMutableArray*)imgArray{
    if (!self.networkQueue){
        self.networkQueue = [[ASINetworkQueue alloc] init];
    }
    [self.networkQueue reset];
    self.progressValueLabel.text = @"0 %";
    self.lblImageUplodInfo.text  = @"Processing..."; 
    self.networkQueue.shouldCancelAllRequestsOnFailure = NO;
    [self.networkQueue setRequestDidFailSelector:@selector(imageUploadFailed:)];
    [self.networkQueue setQueueDidFinishSelector:@selector(imageUploadComplete:)];
    [self.networkQueue setRequestDidFinishSelector:@selector(imageUploadRequestComplete:)];
    [self.progressView performSelectorOnMainThread:@selector(setProgress:) withObject:nil waitUntilDone:YES];
    [self.progressValueLabel performSelectorOnMainThread:@selector(setText:) withObject:@"0 %" waitUntilDone:YES];
    [self.networkQueue setUploadProgressDelegate:self.progressView];
    self.progressView.progress=0.0f;
    self.networkQueue.shouldCancelAllRequestsOnFailure = NO;
    [self.networkQueue setDownloadProgressDelegate:self];
    [self.networkQueue setShowAccurateProgress:YES];
    [self.networkQueue setDelegate:self];


    self.lblImageUplodInfo.text=@"Uploading..";
    [self.networkQueue setShowAccurateProgress:YES];
    [self.networkQueue setDelegate:self];


    for(int i=0;i<[imgArray count];i++)
    {
        if([[[imgArray objectAtIndex:i] objectForKey:@"isSync"] isEqualToString:@"0"])
        {
             ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[WebService getAddPhoto]]];
             [request setUserInfo:[NSDictionary dictionaryWithDictionary:[imgArray objectAtIndex:i]]];
             [request addPostValue:project_id forKey:@"project_id"];
             [request addPostValue:[[imgArray objectAtIndex:i] valueForKey:@"vComments"] forKey:@"comment"];
             NSData *imageData = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:[[imgArray objectAtIndex:i] valueForKey:@"vPhoto"]]);
             NSString *encodedString = [imageData base64EncodingWithLineLength:[imageData length]];
             [request addPostValue:encodedString forKey:@"Photo"];
             [request setDelegate:self];
             [request setTimeOutSeconds:300]; 
             [self.networkQueue addOperation:request];

 }
[self.networkQueue go];
}
于 2013-03-06T12:46:20.930 に答える