我已經學會二方法(可能還有更多的..)上傳圖像服務器..哪個是更好的(快)的方式來上傳圖片服務器上
1)創建的NSData,並將其添加到請求體
2)創建字節數組,並將其發送在JSON等簡單陣列
1)創建的NSData並將其加入到請求主體
從圖像創建的NSData使用此代碼
NSData *imageData = UIImagePNGRepresentation(myimage);
,比請求主體
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
[body appendData:[NSData dataWithData:imageData]];
[request setHTTPBody:body];
執行請求,並添加圖片,將在服務器上上傳。
2)創建字節數組,並將其發送在JSON等簡單陣列
創建圖像的字節數組
NSData *imageData = UIImagePNGRepresentation(myimage);
const unsigned char *bytes = [imageData bytes];
NSUInteger length = [imageData length];
NSMutableArray *byteArray = [NSMutableArray array];
for (NSUInteger i = 0; i<length; i++)
{
[byteArray addObject:[NSNumber numberWithUnsignedChar:bytes[i]]];
}
,也比使用JSON像任何其他陣列
發送它在請求但是這是更好的解決方案或有另一種更快的方式..