그래서이 문제도 있지만 아이폰에서 레일 사이트에 업로드하는 방법입니다. 그들이 사용하고있는 보석에 관해서는 레일즈에 이미지를 업로드하는 법을 배워야하기 때문에 아래 코드가 문제가 될 수도 있습니다. 코드는 다음과 같습니다
그런 다음 모든 매개 변수를 요청과 함께 전송해야하는 사전에 추가하십시오. 이미지가 있기 때문에 웹 브라우저가 작동하는 방식 일시적으로 파일 시스템에 기록 될 필요가 있다는
는
// add params (all params are strings)
for (NSString *param in parameters) {
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", param] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"%@\r\n", [parameters objectForKey:param]] dataUsingEncoding:NSUTF8StringEncoding]];
}
//Compress the data
NSString *FileParamConstant = @"image";
// add image data
CGFloat compression = 0.9f;
CGFloat maxCompression = 0.1f;
int maxFileSize = 250*1024;
NSData *imageData = [[NSData alloc] initWithContentsOfFile:imagePath];
while ([imageData length] > maxFileSize && compression > maxCompression)
{
compression -= 0.1;
imageData = UIImageJPEGRepresentation([UIImage imageNamed:imagePath], compression);
}
if (imageData) {
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"image.jpg\"\r\n", FileParamConstant] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: image/jpeg\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:imageData];
[body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
}
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the reqeust
[request setHTTPBody:body];
// set URL
[request setURL:[NSURL URLWithString:[[URLLibrary sharedInstance] getCreateFeedURL]]];
NSURLResponse* response;
NSError* error;
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
make gui changes saying things worked
}];
참고. 이것은 아이폰에서 이미지를 레일 사이트에 업로드하는 방법입니다.
ASIHttpRequest를 사용하고 있습니까? – Dex
우리는 ASIFormDataRequest를 사용하고 있습니다 ... – picardo