首页 文章

Carrierwave“图像如何不能为空”您不能上传“\”文件?

提问于
浏览
0

我越来越

(lldb)po operation.responseString {“errors”:{“image”:[“不能为空”,“你不允许上传\”\“文件,允许的类型:jpg,jpeg,gif,png” ]}}

上传以创建具有图像参数以及名称和描述的新组 .

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

我是否需要更改Carrierwave设置,或者我的obj-c代码中缺少某些内容?

1 回答

  • 0

    名称中存在空格问题 . 我使用obj-c函数将timestamp作为文件名 .

相关问题