本文整理汇总了Java中org.springframework.web.multipart.commons.CommonsMultipartFile.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java CommonsMultipartFile.getInputStream方法的具体用法?Java CommonsMultipartFile.getInputStream怎么用?Java CommonsMultipartFile.getInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.multipart.commons.CommonsMultipartFile
的用法示例。
在下文中一共展示了CommonsMultipartFile.getInputStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: upload
import org.springframework.web.multipart.commons.CommonsMultipartFile; //导入方法依赖的package包/类
@RequestMapping(value = "/file/upload/{uploadId}", method = RequestMethod.POST)
@ResponseBody
public FileDto upload(@PathVariable String uploadId,
@RequestParam("data") CommonsMultipartFile multipart, HttpServletRequest request,
HttpServletResponse response) {
OutputStream out = null;
InputStream in = null;
try {
out = this.store.write(uploadId, multipart.getOriginalFilename(), multipart.getContentType());
in = multipart.getInputStream();
IOUtils.copy(in, out);
return this.store.getFileBean(uploadId);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
}
示例2: storeFile
import org.springframework.web.multipart.commons.CommonsMultipartFile; //导入方法依赖的package包/类
public String storeFile(CommonsMultipartFile file, String userId,
String postTimestamp) {
try {
ObjectMetadata omd = new ObjectMetadata();
omd.setContentType("application/octet-stream");
omd.addUserMetadata("originalfilename", file.getOriginalFilename());
String path = "files/" + userId + "_" + postTimestamp.replace(':', '_') + "_" + file.getOriginalFilename();
PutObjectRequest request = new PutObjectRequest(BUCKET_NAME,
path,
file.getInputStream(), omd);
s3client.putObject(request);
s3client.setObjectAcl(BUCKET_NAME, path, CannedAccessControlList.PublicRead);
return "http://s3.amazonaws.com/" + BUCKET_NAME + "/" + path;
} catch (IOException e) {
return null;
}
}
示例3: storePicture
import org.springframework.web.multipart.commons.CommonsMultipartFile; //导入方法依赖的package包/类
public String storePicture(CommonsMultipartFile file, String userId,
String postTimestamp) {
try {
ObjectMetadata omd = new ObjectMetadata();
omd.setContentType("application/octet-stream");
omd.addUserMetadata("originalfilename", file.getOriginalFilename());
String path = "pictures/" + userId + "_" + postTimestamp.replace(':', '_') + "_" + file.getOriginalFilename();
PutObjectRequest request = new PutObjectRequest(BUCKET_NAME,
path,
file.getInputStream(), omd);
s3client.putObject(request);
s3client.setObjectAcl(BUCKET_NAME, path, CannedAccessControlList.PublicRead);
return "http://s3.amazonaws.com/" + BUCKET_NAME + "/" + path;
} catch (IOException e) {
return null;
}
}
示例4: convertFilesToMap
import org.springframework.web.multipart.commons.CommonsMultipartFile; //导入方法依赖的package包/类
/**
* This method converts the uploaded files into a map where the key is the
* file name and the value is the file content.
*/
public synchronized static Map<String, String> convertFilesToMap(CommonsMultipartFile[] fileInputList ) {
Map<String, String> fileMap = new LinkedHashMap<String, String>();
CommonsMultipartFile tmpMultiFile;
String tmpCharset;
fileNameCounterMap.clear();
for (int i = 0; i < fileInputList.length; i++) {
tmpMultiFile = fileInputList[i];
try {
if (tmpMultiFile != null && !tmpMultiFile.isEmpty() && tmpMultiFile.getInputStream() != null) {
tmpCharset = CrawlUtils.extractCharset(tmpMultiFile.getInputStream());
fileMap.put(
getFileName(tmpMultiFile.getOriginalFilename()),
tmpMultiFile.getFileItem().getString(tmpCharset));
}
} catch (IOException e) {}
}
return fileMap;
}
示例5: uploadFileToS3
import org.springframework.web.multipart.commons.CommonsMultipartFile; //导入方法依赖的package包/类
/**
* Upload the profile pic to S3 and return it's URL
* @param profilePic
* @return The fully-qualified URL of the photo in S3
* @throws IOException
*/
public String uploadFileToS3(CommonsMultipartFile profilePic) throws IOException {
// Profile pic prefix
String prefix = config.getProperty(ConfigProps.S3_PROFILE_PIC_PREFIX);
// Date string
String dateString = new SimpleDateFormat("ddMMyyyy").format(new java.util.Date());
String s3Key = prefix + "/" + dateString + "/" + UUID.randomUUID().toString() + "_" + profilePic.getOriginalFilename();
// Get bucket
String s3bucket = config.getProperty(ConfigProps.S3_UPLOAD_BUCKET);
// Create a ObjectMetadata instance to set the ACL, content type and length
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType(profilePic.getContentType());
metadata.setContentLength(profilePic.getSize());
// Create a PutRequest to upload the image
PutObjectRequest putObject = new PutObjectRequest(s3bucket, s3Key, profilePic.getInputStream(), metadata);
// Put the image into S3
s3Client.putObject(putObject);
s3Client.setObjectAcl(s3bucket, s3Key, CannedAccessControlList.PublicRead);
return "http://" + s3bucket + ".s3.amazonaws.com/" + s3Key;
}
示例6: handleRequestInternal
import org.springframework.web.multipart.commons.CommonsMultipartFile; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
Locale locale = sessionHandler.getCurrentLocale(request);
ObjectNode uploadResult = null;
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
CommonsMultipartFile cFile = (CommonsMultipartFile) multipartRequest.getFile("file");
String errorMessage = null;
if (cFile != null && cFile.getSize() > 0) {
if (cFile.getSize() < getMaxUploadSize()) {
try {
// create a binary content TO
AttachmentTO binContent = new AttachmentStreamTO(cFile.getInputStream(),
AttachmentStatus.UPLOADED);
binContent.setMetadata(new ContentMetadata());
binContent.getMetadata().setFilename(cFile.getOriginalFilename());
binContent.setContentLength(cFile.getSize());
ResourceStoringManagement rsm = ServiceLocator
.findService(ResourceStoringManagement.class);
Attachment attachment = rsm.storeAttachment(binContent);
// save attachment IDs in session to allow removing attachments that are removed
// from the note before publishing
// we do not do this via separate requests because the ownership is not checked
// when deleting the attachment
Set<Long> uploadedFiles = CreateBlogPostFeHelper
.getUploadedAttachmentsFromSession(request);
uploadedFiles.add(attachment.getId());
uploadResult = CreateBlogPostFeHelper.createAttachmentJSONObject(attachment);
} catch (ResourceStoringManagementException e) {
errorMessage = getUploadExceptionErrorMessage(request, e, locale);
}
} else {
errorMessage = ResourceBundleManager.instance().getText(
"error.blogpost.upload.filesize.limit", locale,
FileUtils.byteCountToDisplaySize(getMaxUploadSize()));
}
} else {
errorMessage = ResourceBundleManager.instance().getText(
"error.blogpost.upload.empty.file", locale);
}
ObjectNode jsonResponse;
if (errorMessage != null) {
jsonResponse = JsonRequestHelper.createJsonErrorResponse(errorMessage);
} else {
jsonResponse = JsonRequestHelper.createJsonSuccessResponse(null, uploadResult);
}
return ControllerHelper.prepareModelAndViewForJsonResponse(multipartRequest, response,
jsonResponse, true);
}