use of com.liferay.portal.kernel.upload.UploadPortletRequest in project liferay-ide by liferay.
the class BaseKBPortlet method addTempAttachment.
public void addTempAttachment(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long resourcePrimKey = ParamUtil.getLong(actionRequest, "resourcePrimKey");
String sourceFileName = uploadPortletRequest.getFileName("file");
InputStream inputStream = null;
try {
inputStream = uploadPortletRequest.getFileAsStream("file");
String mimeType = uploadPortletRequest.getContentType("file");
KBArticleServiceUtil.addTempAttachment(themeDisplay.getScopeGroupId(), resourcePrimKey, sourceFileName, KnowledgeBaseConstants.TEMP_FOLDER_NAME, inputStream, mimeType);
} finally {
StreamUtil.cleanUp(inputStream);
}
}
use of com.liferay.portal.kernel.upload.UploadPortletRequest in project sw360portal by sw360.
the class UserPortlet method getUsersFromRequest.
private List<UserCSV> getUsersFromRequest(PortletRequest request, String fileUploadFormId) throws IOException, TException {
final UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
final InputStream stream = uploadPortletRequest.getFileAsStream(fileUploadFormId);
Reader reader = new InputStreamReader(stream);
CSVFormat format = CommonUtils.sw360CsvFormat;
CSVParser parser = new CSVParser(reader, format);
List<CSVRecord> records;
records = parser.getRecords();
if (records.size() > 0) {
// Remove header
records.remove(0);
}
return getUsersFromCSV(records);
}
use of com.liferay.portal.kernel.upload.UploadPortletRequest in project sw360portal by sw360.
the class AttachmentPortletUtils method uploadAttachmentPartFromRequest.
private boolean uploadAttachmentPartFromRequest(PortletRequest request, String fileUploadName) throws IOException, TException {
final UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
final InputStream stream = uploadPortletRequest.getFileAsStream(fileUploadName);
final ResumableUpload resumableUpload = ResumableUpload.from(uploadPortletRequest);
AttachmentContent attachment = null;
if (resumableUpload.isValid()) {
final AttachmentStreamConnector attachmentStreamConnector = getConnector();
attachment = getAttachmentContent(resumableUpload, stream);
if (attachment != null) {
try {
attachmentStreamConnector.uploadAttachmentPart(attachment, resumableUpload.getChunkNumber(), stream);
} catch (TException e) {
log.error("Error saving attachment part", e);
return false;
}
}
}
return attachment != null;
}
use of com.liferay.portal.kernel.upload.UploadPortletRequest in project liferay-ide by liferay.
the class JukeboxPortlet method addArtist.
public void addArtist(ActionRequest request, ActionResponse response) throws Exception {
UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
String name = ParamUtil.getString(uploadPortletRequest, "name");
String bio = ParamUtil.getString(uploadPortletRequest, "bio");
InputStream inputStream = uploadPortletRequest.getFileAsStream("file");
ServiceContext serviceContext = ServiceContextFactory.getInstance(Artist.class.getName(), uploadPortletRequest);
try {
ArtistServiceUtil.addArtist(name, bio, inputStream, serviceContext);
SessionMessages.add(request, "artistAdded");
String redirect = ParamUtil.getString(uploadPortletRequest, "redirect");
response.sendRedirect(redirect);
} catch (Exception e) {
SessionErrors.add(request, e.getClass().getName());
if (e instanceof ArtistNameException || e instanceof PrincipalException) {
response.setRenderParameter("jspPage", "/html/artists/edit_artist.jsp");
} else {
response.setRenderParameter("jspPage", "/html/error.jsp");
}
}
}
use of com.liferay.portal.kernel.upload.UploadPortletRequest in project liferay-ide by liferay.
the class JukeboxPortlet method addSong.
public void addSong(ActionRequest request, ActionResponse response) throws Exception {
UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request);
long albumId = ParamUtil.getLong(uploadPortletRequest, "albumId");
String name = ParamUtil.getString(uploadPortletRequest, "name");
InputStream songInputStream = uploadPortletRequest.getFileAsStream("songFile");
String songFileName = uploadPortletRequest.getFileName("songFile");
InputStream lyricsInputStream = uploadPortletRequest.getFileAsStream("lyricsFile");
String lyricsFileName = uploadPortletRequest.getFileName("lyricsFile");
ServiceContext serviceContext = ServiceContextFactory.getInstance(Song.class.getName(), uploadPortletRequest);
try {
SongServiceUtil.addSong(albumId, name, songFileName, songInputStream, lyricsFileName, lyricsInputStream, serviceContext);
SessionMessages.add(request, "songAdded");
String redirect = ParamUtil.getString(uploadPortletRequest, "redirect");
response.sendRedirect(redirect);
} catch (Exception e) {
SessionErrors.add(request, e.getClass().getName());
if (e instanceof SongNameException || e instanceof DuplicatedSongException || e instanceof PrincipalException) {
response.setRenderParameter("jspPage", "/html/songs/edit_song.jsp");
} else {
response.setRenderParameter("jspPage", "/html/error.jsp");
}
}
}
Aggregations