我的Config.groovy文件显示:
resource 'ktm-documents' config{
serviceName ='docCompositeService'
// methods = ['list']
representation {
mediaTypes = ["application/vnd.hedtech.v1+json", "application/json", "multipart/form-data"]
marshallers{
jsonBeanMarshaller{
supports net.hedtech.banner.decorator.DocDecorator
}
jsonBeanMarshaller{
supports net.hedtech.banner.decorator.Indexes
}
}
extractor = new net.hedtech.banner.extractor.DocExtractor()
}
}
提取器是:
class DocExtractor implements RequestExtractor{
@Override
Map extract(HttpServletRequest request) {
print("========== My EXTRACTOR ========")
MultipartHttpServletRequest mpr
Map responseMap = [:]
print request
try {
print "Here's abc " + request.getParameter("abc")
mpr = (MultipartHttpServletRequest) request;
CommonsMultipartFile file = (CommonsMultipartFile) mpr.getFile("file");
if (file.isEmpty()) {
responseMap.put("error","file empty hai")
} else {
responseMap.put("file", file)
}
print responseMap.values()
} catch (Exception e) {
e.printStackTrace()
}
}
}
当尝试从服务的create()中的提取器中获取从请求中提取的文件时,我得到“无法获取属性'文件'为null”错误。
服务中的create()方法:
def create(Map params){
print params
File f = params.file
return ["File Uploaded!"]
}
对此有何想法?