本文整理汇总了Java中org.springframework.web.multipart.commons.CommonsMultipartFile.getOriginalFilename方法的典型用法代码示例。如果您正苦于以下问题:Java CommonsMultipartFile.getOriginalFilename方法的具体用法?Java CommonsMultipartFile.getOriginalFilename怎么用?Java CommonsMultipartFile.getOriginalFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.multipart.commons.CommonsMultipartFile
的用法示例。
在下文中一共展示了CommonsMultipartFile.getOriginalFilename方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveFile
import org.springframework.web.multipart.commons.CommonsMultipartFile; //导入方法依赖的package包/类
public String saveFile(CommonsMultipartFile file) throws IOException {
String filePath = "/tmp/neilren4j_ip_" + new Date().getTime() + file.getOriginalFilename();
File newFile = new File(filePath);
//通过CommonsMultipartFile的方法直接写文件(注意这个时候)
file.transferTo(newFile);
return filePath;
}
示例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: documentAdjuntar
import org.springframework.web.multipart.commons.CommonsMultipartFile; //导入方法依赖的package包/类
@RequestMapping(value = "/{tascaId}/document/{documentCodi}/adjuntar", method = RequestMethod.POST)
public String documentAdjuntar(
HttpServletRequest request,
@PathVariable String tascaId,
@PathVariable String documentCodi,
@RequestParam(value = "arxiu", required = false) final CommonsMultipartFile arxiu,
@RequestParam(value = "data", required = false) Date data,
Model model) {
try {
byte[] contingutArxiu = IOUtils.toByteArray(arxiu.getInputStream());
String nomArxiu = arxiu.getOriginalFilename();
ExpedientTascaDto tasca = tascaService.findAmbIdPerTramitacio(tascaId);
if (!tasca.isValidada()) {
MissatgesHelper.error(request, getMessage(request, "error.validar.dades"));
} else if (!expedientService.isExtensioDocumentPermesa(nomArxiu)) {
MissatgesHelper.error(request, getMessage(request, "error.extensio.document"));
} else if (nomArxiu.isEmpty() || contingutArxiu.length == 0) {
MissatgesHelper.error(request, getMessage(request, "error.especificar.document"));
} else {
accioDocumentAdjuntar(
request,
tascaId,
documentCodi,
nomArxiu,
contingutArxiu,
(data == null) ? new Date() : data).toString();
}
} catch (Exception ex) {
MissatgesHelper.error(request, getMessage(request, "error.guardar.document") + ": " + ex.getLocalizedMessage());
logger.error("Error al adjuntar el document a la tasca(" +
"tascaId=" + tascaId + ", " +
"documentCodi=" + documentCodi + ")",
ex);
}
return mostrarInformacioTascaPerPipelles(
request,
tascaId,
model,
"document");
}
示例5: documentModificarPost
import org.springframework.web.multipart.commons.CommonsMultipartFile; //导入方法依赖的package包/类
@RequestMapping(value="/{expedientId}/documentAdjuntar", method = RequestMethod.POST)
public String documentModificarPost(
HttpServletRequest request,
@PathVariable Long expedientId,
@RequestParam(value = "accio", required = true) String accio,
@ModelAttribute DocumentExpedientCommand command,
@RequestParam(value = "arxiu", required = false) final CommonsMultipartFile arxiu,
@RequestParam(value = "processInstanceId", required = true) String processInstanceId,
BindingResult result,
SessionStatus status,
Model model) {
try {
new DocumentModificarValidator().validate(command, result);
if (result.hasErrors() || arxiu == null || arxiu.isEmpty()) {
if (arxiu == null || arxiu.isEmpty()) {
MissatgesHelper.error(request, getMessage(request, "error.especificar.document"));
}
model.addAttribute("processInstanceId", processInstanceId);
return "v3/expedientDocumentNou";
}
byte[] contingutArxiu = IOUtils.toByteArray(arxiu.getInputStream());
String nomArxiu = arxiu.getOriginalFilename();
command.setNomArxiu(nomArxiu);
command.setContingut(contingutArxiu);
expedientService.crearModificarDocument(expedientId, processInstanceId, null, command.getNom(), command.getNomArxiu(), command.getDocId(), command.getContingut(), command.getData());
MissatgesHelper.success(request, getMessage(request, "info.document.guardat") );
} catch (Exception ex) {
logger.error("No s'ha pogut crear el document: expedientId: " + expedientId, ex);
MissatgesHelper.error(request, getMessage(request, "error.proces.peticio") + ": " + ex.getLocalizedMessage());
}
return modalUrlTancar(false);
}
示例6: 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;
}
示例7: doAddPost
import org.springframework.web.multipart.commons.CommonsMultipartFile; //导入方法依赖的package包/类
@RequestMapping(value = "/postwrite", method = RequestMethod.POST)
public String doAddPost( HttpServletRequest request,
@ModelAttribute("post") Post post, @RequestParam CommonsMultipartFile[] imageName,
Principal principal) {
// saveDirectory = new File(".").getCanonicalPath(); retunt location C://tomcat-8/bin
String saveDirectory = context.getRealPath("/resources/img/postImages");
System.out.println("total file:"+ imageName.length);
try {
if (imageName != null && imageName.length > 0) {
for (CommonsMultipartFile aFile : imageName){
String filename = UUID.randomUUID().toString() + aFile.getOriginalFilename();
post.setBannerImageName(filename);
if (!aFile.getOriginalFilename().equals("")) {
aFile.transferTo(new File(saveDirectory+"/" + filename));
}
}
}
}
catch (Exception ex) {
ex.printStackTrace();
}
String name = principal.getName();
postService.save(post, name);
return "redirect:/index.html";
}
示例8: documentAdjuntar2
import org.springframework.web.multipart.commons.CommonsMultipartFile; //导入方法依赖的package包/类
@RequestMapping(value = "/{tascaId}/{tascaId2}/document/{documentCodi}/adjuntar", method = RequestMethod.POST)
public String documentAdjuntar2(
HttpServletRequest request,
@PathVariable String tascaId,
@PathVariable String tascaId2,
@PathVariable String documentCodi,
@RequestParam(value = "arxiu", required = false) final CommonsMultipartFile arxiu,
@RequestParam(value = "data", required = false) Date data,
Model model) {
try {
byte[] contingutArxiu = IOUtils.toByteArray(arxiu.getInputStream());
String nomArxiu = arxiu.getOriginalFilename();
ExpedientTascaDto tasca = tascaService.findAmbIdPerTramitacio(tascaId);
if (!tasca.isValidada()) {
MissatgesHelper.error(request, getMessage(request, "error.validar.dades"));
} else if (!expedientService.isExtensioDocumentPermesa(nomArxiu)) {
MissatgesHelper.error(request, getMessage(request, "error.extensio.document"));
} else if (nomArxiu.isEmpty() || contingutArxiu.length == 0) {
MissatgesHelper.error(request, getMessage(request, "error.especificar.document"));
} else {
accioDocumentAdjuntar(
request,
tascaId,
documentCodi,
nomArxiu,
contingutArxiu,
(data == null) ? new Date() : data).toString();
}
} catch (Exception ex) {
MissatgesHelper.error(request, getMessage(request, "error.guardar.document") + ": " + ex.getLocalizedMessage());
logger.error("Error al adjuntar el document a la tasca(" +
"tascaId=" + tascaId + ", " +
"documentCodi=" + documentCodi + ")",
ex);
}
return mostrarInformacioTascaPerPipelles(
request,
tascaId,
model,
"document");
}