String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
PrintWriter out = null;
try {
out = response.getWriter();
FileUploadServiceClient client =
new FileUploadServiceClient(configurationContext, serverURL, cookie);
response.setContentType("text/plain; charset=utf-8");
Set<String> keys = fileItemsMap.get().keySet();
boolean multiItems = false;
if (fileItemsMap.get().size() > 1) {
multiItems = true;
}
// Process the uploaded items
UploadedFileItem[] uploadedFileItems = new UploadedFileItem[fileItemsMap.get().size()];
Iterator<String> iterator = keys.iterator();
int i = 0;
while (iterator.hasNext()) {
String fieldName = iterator.next();
String fileName = fileItemsMap.get().get(fieldName).get(0).getFileItem().getName();
if ((fileName == null || fileName.length() == 0) && multiItems) {
continue;
}
FileItemData fileItemData = fileItemsMap.get().get(fieldName).get(0);
UploadedFileItem uploadedFileItem = new UploadedFileItem();
uploadedFileItem.setDataHandler(fileItemData.getDataHandler());
uploadedFileItem.setFileName(fileName);
uploadedFileItem.setFileType("");
uploadedFileItems[i] = uploadedFileItem;
i++;
}
String[] uuidArray = client.uploadFiles(uploadedFileItems);
StringBuffer uuids = new StringBuffer();
for (String uuid : uuidArray) {
uuids.append(uuid).append(",");
}
out.write(uuids.toString().substring(0, uuids.length() - 1));