当前位置: 首页>>代码示例>>Java>>正文


Java CommonsMultipartFile.getInputStream方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:Putnami,项目名称:putnami-web-toolkit,代码行数:20,代码来源:FileTransfertController.java

示例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;
	}

}
 
开发者ID:Moliholy,项目名称:Fancraft,代码行数:25,代码来源:S3DAO.java

示例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;
	}

}
 
开发者ID:Moliholy,项目名称:Fancraft,代码行数:25,代码来源:S3DAO.java

示例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;
}
 
开发者ID:Tanaguru,项目名称:Tanaguru,代码行数:23,代码来源:UploadAuditSetUpCommandHelper.java

示例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;
  }
 
开发者ID:awslabs,项目名称:amediamanager,代码行数:33,代码来源:DynamoDbUserDaoImpl.java

示例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);
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:55,代码来源:AttachmentUploadController.java


注:本文中的org.springframework.web.multipart.commons.CommonsMultipartFile.getInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。