在iPhone中使用带有userid参数的base64 haxcode将图像上传到服务器 [英] Uploading image to server with base64 haxcode with userid parameter in iPhone

查看:144
本文介绍了在iPhone中使用带有userid参数的base64 haxcode将图像上传到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这段代码,但问题是它在nsdata转换块中对Haxcode进行编码我要发送的代码是我用userid得到的代码,它是固定整数。请帮忙。

I'm using this code but problem is that it encodes the Haxcode in nsdata conversion block I want to send same has code which I'm getting with userid which is fixed integer. Please help.

 NSData *imageData = [NSData dataWithData:UIImageJPEGRepresentation(image1, 0)];
    //image.image=image1;

    [Base64 initialize];
    NSString *b64EncStr = [Base64 encode:imageData];

    NSLog(@"encoded.%@",b64EncStr);




     NSURL *url = [[NSURL alloc] initWithString:updateimageURL];
    NSMutableURLRequest *req = [[NSMutableURLRequest alloc]initWithURL:url];
    [req setHTTPMethod:@"POST"];

    NSString *trimmed = [b64EncStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];



    paramDataString = [NSString stringWithFormat:@"Id=%d&FromString=%@",100,trimmed];

    NSLog(@"%@",paramDataString);


    NSData* aData = [paramDataString dataUsingEncoding:NSUTF8StringEncoding];


      [req setHTTPBody: aData];

    NSURLConnection *theConnection=[[NSURLConnection alloc]initWithRequest:req delegate:self];
    if (theConnection)
    {
        NSMutableData *data = [[NSMutableData alloc] init];
        self.receivedData=data;
        [data release];

    }
    else {

        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil message:@"Check your networking configuration." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    }

    [url release];
    [req release];

它以正确的方式建立URL连接,但响应是服务器错误。

It is making the URL connection in right way but response is server error.

推荐答案

首先将 UImage 转换为 NSData 从NSData到base64string,然后将其传递给您的Web服务

First Convert UImage to NSData and from NSData to base64string and then pass that to your Webservice

finalImagePath = [imageData base64EncodedString];

NSString *strImageData = [finalImagePath stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];

然后将 strImageData 发送到您的webserivce。

and then send strImageData to your webserivce.

从服务器使用时重新使用

While retriving from server use

NSString *strImageData = [finalImagePath stringByReplacingOccurrencesOfString:@"%2B" withString:@"+"];

这篇关于在iPhone中使用带有userid参数的base64 haxcode将图像上传到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆