-2

In my application i got latitude and longitude.Now on a click on a button i have to upload this co-ordinates into server. If i want to upload a position i have to upload a txt file containing the coordinates in the described format. The text file have to be upload as a Base64 coded stream like a picture file, e.g. jpg or png.

Here is my code:

NSDate* date = [NSDate date];
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:MM:SS"];
str = [formatter stringFromDate:date];


lg= [NSString stringWithFormat:@"Lattitude is: %.8f", coord.longitude];
ls= [NSString stringWithFormat:@"Longitude is: %.8f", coord.latitude];

valueString=[NSString stringWithFormat:@"%@ \n %@ \n %@",lg,ls,str];
rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

Hope this might solve your problem

NSString *decodeString = @"Sample Data";

Encode String

NSData *encodeData = [decodeString dataUsingEncoding:NSUTF8StringEncoding];
NSString *base64String = [encodeData base64EncodedStringWithOptions:0];
NSLog(@"Encode String: %@", base64String);

Decode String

NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:base64String options:0];
NSString *decodedString = [[NSString alloc] initWithData:decodedData encoding:NSUTF8StringEncoding];
NSLog(@"Decode String: %@", base64String);  
Jay Gajjar
  • 2,661
  • 2
  • 21
  • 35
  • so file format will be what png or jpeg? – user3218052 May 01 '14 at 09:19
  • @user3218052: Base64 is an encoding scheme for arbitrary binary data. It has nothing to do with PNG or JPEG. – Martin R May 01 '14 at 09:22
  • so simply i write ur code it convert and i got output as Encode String: TGF0dGl0dWRlIGlzOiAwLjAwMDAwMDAwIAogTG9uZ2l0dWRlIGlzOiAwLjAwMDAwMDAwIAogMjAxNC0wNS0wMSAxNDowNTo2MA== – user3218052 May 01 '14 at 09:26
  • now i have to send it server so what shoild i do can i pass it as image – user3218052 May 01 '14 at 09:27
  • as @MartinR said you can pass any data. I will be converted to binary – Jay Gajjar May 01 '14 at 09:32
  • @MartinR i have two parameter one is Filetype and other is content in which file type is like png jpeg and content have encoded string value so if i set filetype=@"png"; and content=base64string then it will work ? – user3218052 May 01 '14 at 09:34
  • @JayGajjar i have two parameter one is Filetype and other is content in which file type is like png jpeg and content have encoded string value so if i set filetype=@"png"; and content=base64string then will it work ? – user3218052 May 01 '14 at 09:42
  • just try i dont know what kind of code is written on your server – Jay Gajjar May 01 '14 at 09:43
  • @user3218052: Your question is about uploading coordinates in Base64 encoding. I cannot see what that has to do with image types like PNG or JPEG. – Martin R May 01 '14 at 09:43
  • @MartinR please look at my question again its my client requirement so have to do can u please provide me a code by which i can move ahead – user3218052 May 01 '14 at 09:49