사용자가 레일 기반 웹 서비스에 사진을 업로드 할 수있게 해주는 아이폰 앱을 만들고 있습니다. 내 장치에서 응용 프로그램을 테스트 중이므로 사진을 찍은 다음 게시 할 수 있습니다. 그러나 photData는 null로 반환됩니다.iphone 앱에서 레일 서버로 사진 업로드
post = {
content = Test;
"created_at" = "2013-08-02T19:15:05Z";
id = 2;
photo = {
thumb = {
url = "<null>";
};
"thumb_retina" = {
url = "<null>";
};
url = "<null>";
};
};
success = 1;
}
실제로 서버에 데이터를 게시하는 구현에서 실종 무엇 : 이 게시물을 만든 후 Xcode의 로그는?
레일 사이드에서 carrierwave 및 miniMagick을 업 로더로 사용하고 있습니다. 안개 저장소를 사용하여 모든 것을 S3에 저장합니다. (즉 이내로 할의 목표는하지만 그 일이되지 않습니다.) 내 포스트 모델은 이러한 속성이 있습니다
@property (nonatomic, strong) NSString *content;
@property (nonatomic, strong) NSString *thumbnailUrl;
@property (nonatomic, strong) NSString *largeUrl;
@property (nonatomic, strong) NSData *photoData;
저장 방법은 다음과 같이이다 :
- (void)saveWithProgressAtLocation:(CLLocation *)location
withBlock:(void (^)(CGFloat))progressBlock completion:(void (^)(BOOL, NSError *))completionBlock {
if (!self.content) self.content = @"";
NSDictionary *params = @{
@"post[content]" : self.content,
};
NSURLRequest *postRequest = [[APIClient sharedClient] multipartFormRequestWithMethod:@"POST"
path:@"/posts"
parameters:params
constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
{
[formData appendPartWithFileData:self.photoData
name:@"post[photo]"
fileName:@""
mimeType:@"image/png"];
}];
AFHTTPRequestOperation *operation = [[AFJSONRequestOperation alloc] initWithRequest:postRequest];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
CGFloat progress = ((CGFloat)totalBytesWritten)/totalBytesExpectedToWrite;
progressBlock(progress);
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if (operation.response.statusCode == 200 || operation.response.statusCode == 201) {
NSLog(@"Created, %@", responseObject);
NSDictionary *updatedPost = [responseObject objectForKey:@"post"];
[self updateFromJSON:updatedPost];
[self notifyCreated];
completionBlock(YES, nil);
} else {
completionBlock(NO, nil);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
completionBlock(NO, error);
}];
[[APIClient sharedClient] enqueueHTTPRequestOperation:operation];
}
그리고 실제 방법을 그 사진 뷰 컨트롤러의 저장 위치가 다음과 같습니다.
- (void)save:(id)sender {
Post *post = [[Post alloc] init];
post.content = self.contentTextField.text;
post.photoData = UIImagePNGRepresentation(self.imageView.image);
[self.view endEditing:YES];
ProgressView *progressView = [ProgressView presentInWindow:self.view.window];
if (location) {
[post saveWithProgressAtLocation:self.locationManager.location withBlock:^(CGFloat progress) {
[progressView setProgress:progress];
} completion:^(BOOL success, NSError *error) {
[progressView dismiss];
if (success) {
[self.navigationController popViewControllerAnimated:YES];
} else {
NSLog(@"ERROR: %@", error);
}
}];
}
문제는 photoData가 서버에 저장되지 않는다는 것입니다. 어떤 아이디어?
처음에는 레일즈에 미리 컴파일 된 기본 사진이 있습니다 : assets/images/nophoto.png - 사진을 찍을 때마다이 기본값이 새 사진을 덮어 쓰고 게시됩니다. 이는 분명히 원하는 것이 아닙니다. 그래서 나는 그것을 삭제했고, 이제는 null이되었습니다. 아이디어가 있으십니까?