objective-ccarrierwaveimage-uploadingafhttpclient

How Carrierwave "image can't be blank" You are not allowed to upload "\" files?


I'm getting

(lldb) po operation.responseString {"errors":{"image":["can't be blank","You are not allowed to upload \"\" files, allowed types: jpg, jpeg, gif, png"]}}

Uploading to create a new group with an image parameter along with name & description.

    NSString *path = [NSString stringWithFormat:@"api/group?name=%@&description=%@&auth_token=%@", name, desc,[AccountService authToken]];


NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", [RequestHelpers basePath]]];

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

NSData *imageData = UIImageJPEGRepresentation(image, 0.25f);
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:path parameters:@{} constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
    NSString *fileName = [NSString stringWithFormat:@"%@", [[NSDate date] description]];
    [formData appendPartWithFileData:imageData name:@"image" fileName:fileName mimeType:@"image/jpeg"];
}];


AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    [self.delegate createdGroupSuccessfully];;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    [self handleOperationFailed:operation action:^{
           //handle failed request
    }];
}];

Do I need to change Carrierwave settings, or am I missing something in my obj-c code?


Solution

  • There was an issue with spaces in the name. I was using an obj-c function for getting timestamp as a file name.