我正在将图片从图库转换为 base64,然后将其上传到“webServices.asmx”。图像在服务器上损坏,还是我的错?我不知道。我尝试将字符串放入:' http ://www.freeformatter.com/base64-encoder.html '并解码字符串并获得正确的图像。
我的代码:
// HTTP POST
NSURL *url = [NSURL URLWithString:@""];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
[httpClient setDefaultHeader:@"Content-Type" value:@"application/x-www-form-urlencoded"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%d", userID], @"userID",
self.imageBase64, @"file",
nil];
[httpClient postPath:@"http://www....../webServices.asmx/saveImageIOS" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *responseString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"\nResponse XML: \n%@", responseString);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error.localizedDescription);
}];
示例 base64 字符串(转换后的图像):
/9j/4AAQSkZJRgABAQAAAQABAAD/4QBYRXhpZgAATU0AKgAAAAgAAgESAAMAAAABAAEAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAABQKADAAQAAAABAAABCAAAAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAEIAUADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eX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