我之前在这个论坛上问这个,但它已经关闭我不知道为什么,所以我再次发布我的问题.在iPhone应用程序中我必须使用Base64编码上传图片,但当我在服务器中查看图片全白(大小= 0x0,54 KO),我确定我的图片的Base64编码是正确的,因为我有一个PHP脚本,我使用它,图片正常显示.这是用于上传的PHP代码:
<?php
$filename = "photo_to_upload.jpg";
$handle = fopen($filename, "r");
$imgbinary = fread($handle, filesize($filename));
$data = base64_encode($imgbinary);
fclose($handle);
?>
<img src="./<?php echo $filename ?>" />
<form action="http://host" method="POST">
<input type="hidden" name="data" value="<?php echo $data?>">
<input type="submit" value="envoyer" />
</form>
Run Code Online (Sandbox Code Playgroud)
和Xcode我用这个:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"photo_to_upload" ofType:@"jpg"];
NSURL *url = [NSURL fileURLWithPath:filePath];
NSData *imageData = [NSData dataWithContentsOfURL:url];
NSURLResponse* response;
NSError* error=nil;
NSMutableData *postData=[[NSMutableData alloc]init];
[postData appendData:[@"data=" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[self base64forData:imageData]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"HOST"]];
[request setHTTPMethod:@"POST"];
[request …Run Code Online (Sandbox Code Playgroud)