2011-08-21 7 views
4

내가 Dragonfly gem.로 구성되어 레일 아이폰에서 이미지를 업로드하려고에서 서버 (잠자리 사용) 레일에 문제는이 오류가 계속된다 : 나는 궁금업로드 이미지는 아이폰

Dragonfly::TempObject must be initialized with a String, a File, a Tempfile, another TempObject, or something that responds to .tempfile

을 이것은 iPhone 또는 다른 것으로부터 전송 된 MIME 유형과 관련이 있습니다. 업로드는 브라우저에서 제대로 작동합니다. 나는 아이폰이나 서버 같은 문제의 근원을 어디에서 찾을 지에 대한 어떤 종류의 지침도 감사 할 것입니다.

감사합니다.

+0

ASIHttpRequest를 사용하고 있습니까? – Dex

+0

우리는 ASIFormDataRequest를 사용하고 있습니다 ... – picardo

답변

0

그래서이 문제도 있지만 아이폰에서 레일 사이트에 업로드하는 방법입니다. 그들이 사용하고있는 보석에 관해서는 레일즈에 이미지를 업로드하는 법을 배워야하기 때문에 아래 코드가 문제가 될 수도 있습니다. 코드는 다음과 같습니다

그런 다음 모든 매개 변수를 요청과 함께 전송해야하는 사전에 추가하십시오. 이미지가 있기 때문에 웹 브라우저가 작동하는 방식 일시적으로 파일 시스템에 기록 될 필요가 있다는

// 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 
         }]; 

참고. 이것은 아이폰에서 이미지를 레일 사이트에 업로드하는 방법입니다.

관련 문제