나는 그것을 내 끝에 시도했다. 우선 이렇게 base64encoding 변환 :
NSString *str64;
if(Image){
NSData *imageData = UIImageJPEGRepresentation(Image,0.75);
str64 = [imageData base64Encoding];
}
그럼 I는 사전에 첨가하고 배열로 사전 I 요청의 본문에 JSON 문자열로 전달할 수 있도록 덧붙였다.
NSMutableArray * ParaArray = [[NSMutableArray alloc] init];
ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
[request setPostValue:[ParaArray JSONRepresentation] forKey:@"bulk_data"];
//[ParaDictionary release];
[ParaArray release];
[request setTimeOutSeconds:20];
[request startSynchronous];
그것은 나를 위해 잘 작동 :이
NSDictionary *ParaDictionary=[NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%@",Userid], @"userid",
[NSString stringWithFormat:@"%@",[Imagename URLEncodedString]], @"imagename",
[NSString stringWithFormat:@"%@",DateNTime], @"datetime",
[NSString stringWithFormat:@"%@",ImageLocation], @"imagelocation",
str64,@"image",
nil]; // set the parameter
[ParaArray addObject:ParaDictionary];
ASIFormDataRequest 사용 후 나는이 조각을 사용하여 서버로 이미지를 보냈다. 나는 그것이 당신을 도울 수 있기를 바랍니다.
데이터는 문자열 형식으로 전달되며 복사하여 붙여 넣기하여 base64Encoding 메서드를 직접 사용할 수 있습니다. 여전히 여기에 있습니다.
- (NSString *) base64Encoding {
return [self base64EncodingWithLineLength:0];
}
- (NSString *) base64EncodingWithLineLength:(NSUInteger) lineLength {
const unsigned char *bytes = [self bytes];
NSMutableString *result = [NSMutableString stringWithCapacity:[self length]];
unsigned long ixtext = 0;
unsigned long lentext = [self length];
long ctremaining = 0;
unsigned char inbuf[3], outbuf[4];
unsigned short i = 0;
unsigned short charsonline = 0, ctcopy = 0;
unsigned long ix = 0;
while(YES) {
ctremaining = lentext - ixtext;
if(ctremaining <= 0) break;
for(i = 0; i < 3; i++) {
ix = ixtext + i;
if(ix < lentext) inbuf[i] = bytes[ix];
else inbuf [i] = 0;
}
outbuf [0] = (inbuf [0] & 0xFC) >> 2;
outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((inbuf [1] & 0xF0) >> 4);
outbuf [2] = ((inbuf [1] & 0x0F) << 2) | ((inbuf [2] & 0xC0) >> 6);
outbuf [3] = inbuf [2] & 0x3F;
ctcopy = 4;
switch(ctremaining) {
case 1:
ctcopy = 2;
break;
case 2:
ctcopy = 3;
break;
}
for(i = 0; i < ctcopy; i++)
[result appendFormat:@"%c", encodingTable[outbuf[i]]];
for(i = ctcopy; i < 4; i++)
[result appendString:@"="];
ixtext += 3;
charsonline += 4;
if(lineLength > 0) {
if(charsonline >= lineLength) {
charsonline = 0;
[result appendString:@"\n"];
}
}
}
return [NSString stringWithString:result];
}
원시 데이터 란 무엇입니까? ASIHTTPRequest의 델리게이트 메소드는 여러분에게 어떤 일이 벌어지고 있는지에 대한 통찰력을 제공합니다. –
대리자 메서드는 배열 유형의 객체에 파일 경로를 추가 한 다음 비동기 호출을 수행하여 웹 서버에 데이터를 전송하지만 데이터를 전송하는 방법을 정확히 알려주지 않았습니다 또는 서버에서 전송되는 데이터 유형 – Robin
ASIHTTPRequestConfig.h에서 DEBUG_FORM_DATA_REQUEST를 1로 설정하면 디버그 데이터가 콘솔에 기록됩니다. – bbarnhart