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


Java MultipartFile.getBytes方法代码示例

本文整理汇总了Java中org.springframework.web.multipart.MultipartFile.getBytes方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartFile.getBytes方法的具体用法?Java MultipartFile.getBytes怎么用?Java MultipartFile.getBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.multipart.MultipartFile的用法示例。


在下文中一共展示了MultipartFile.getBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadResume

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@RequestMapping(value = "/{id}/uploadResume", method = RequestMethod.POST)
@ApiOperation(value = "Add new upload resume")
public String uploadResume(@ApiParam(value = "user Id", required = true) @PathVariable("id") Integer id,
		@ApiParam(value = "Resume File(.pdf)", required = true) @RequestPart("file") MultipartFile file) {

	String contentType = file.getContentType();
	if (!FileUploadUtil.isValidResumeFile(contentType)) {
		return "Invalid pdf File! Content Type :-" + contentType;
	}
	File directory = new File(RESUME_UPLOAD.getValue());
	if (!directory.exists()) {
		directory.mkdir();
	}
	File f = new File(userService.getResumeUploadPath(id));
	try (FileOutputStream fos = new FileOutputStream(f)) {
		byte[] fileByte = file.getBytes();
		fos.write(fileByte);
		return "Success";
	} catch (Exception e) {
		return "Error saving resume for User " + id + " : " + e;
	}
}
 
开发者ID:Code4SocialGood,项目名称:C4SG-Obsolete,代码行数:23,代码来源:UserController.java

示例2: handleFileUpload

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * 上传接口
 * @param file
 * @return
 */
@PostMapping("/upload")
@ResponseBody
public ResponseEntity<String> handleFileUpload(@RequestParam("file") MultipartFile file) {
	File returnFile = null;
    try {
    	File f = new File(file.getOriginalFilename(),  file.getContentType(), file.getSize(),file.getBytes());
    	f.setMd5( MD5Util.getMD5(file.getInputStream()) );
    	returnFile = fileService.saveFile(f);
    	String path = "//"+ serverAddress + ":" + serverPort + "/view/"+returnFile.getId();
    	return ResponseEntity.status(HttpStatus.OK).body(path);
 
    } catch (IOException | NoSuchAlgorithmException ex) {
        ex.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ex.getMessage());
    }
 
}
 
开发者ID:waylau,项目名称:mongodb-file-server,代码行数:23,代码来源:FileController.java

示例3: uploadLogo

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@RequestMapping(value = "/{id}/uploadLogoAsFile", method = RequestMethod.POST)
@ApiOperation(value = "Add new upload Logo as Image File")
public String uploadLogo(@ApiParam(value = "Organization Id", required = true) @PathVariable Integer id,
		@ApiParam(value = "Image File", required = true) @RequestPart("file") MultipartFile file) {

	String contentType = file.getContentType();
	if (!FileUploadUtil.isValidImageFile(contentType)) {
		return "Invalid Image file! Content Type :-" + contentType;
	}
	File directory = new File(LOGO_UPLOAD.getValue());
	if (!directory.exists()) {
		directory.mkdir();
	}
	File f = new File(organizationService.getLogoUploadPath(id));
	try (FileOutputStream fos = new FileOutputStream(f)) {
		byte[] imageByte = file.getBytes();
		fos.write(imageByte);
		return "Success";
	} catch (Exception e) {
		return "Error saving logo for organization " + id + " : " + e;
	}
}
 
开发者ID:Code4SocialGood,项目名称:C4SG-Obsolete,代码行数:23,代码来源:OrganizationController.java

示例4: Data

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public Data(String id ,MultipartFile data,Weaver weaver){
	this.id = id;
	this.date = new Date();
	this.weaver = weaver;
	this.name= "";
	try{
		this.content= data.getBytes();
	}catch(IOException e){
		this.content= null;
	}		
	this.name = data.getOriginalFilename();
	this.name = this.name.replace(" ", "_");
	this.name = this.name.replace("#", "_");
	this.name = this.name.replace("?", "_");	
	this.name = this.name.trim();
	this.type = data.getContentType();
	this.filePath = path+weaver.getId()+File.separator+this.id+File.separator+this.name;		
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:19,代码来源:Data.java

示例5: saveUploadedFiles

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
private String saveUploadedFiles(List<MultipartFile> files) throws IOException {
    if (Files.notExists(Paths.get(UPLOADED_FOLDER))) {
        init();
    }

    String randomPath = "";

    for (MultipartFile file : files) {
        if (file.isEmpty()) {
            continue; //next pls
        }

        byte[] bytes = file.getBytes();

        String fileName = file.getOriginalFilename();
        String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);

        randomPath +=  generateRandomPath() + "." + suffix;

        Path path = Paths.get(UPLOADED_FOLDER + randomPath);
        Files.write(path, bytes);
    }

    return randomPath;
}
 
开发者ID:ziwenxie,项目名称:leafer,代码行数:26,代码来源:FileUploadController.java

示例6: store

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * The storing method should be able to adapt to all types of storing: requests, templates and responses from institutions
 *
 * @param files a list files that will be uploaded
 */
@Override
public boolean store(List<MultipartFile> files, Path path) {
    try {
        for (MultipartFile file : files) {
            if (file.isEmpty()) {
                continue; // give me another one
            }

            byte[] bytes = file.getBytes();

            Files.write(path, bytes);
        }
    } catch (IOException ioe) {
        logger.error(ioe.getStackTrace());

        return false;
    }

    return true;
}
 
开发者ID:CoruptiaUcide,项目名称:va-vedem-api,代码行数:26,代码来源:StorageServiceImpl.java

示例7: setValue

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@Override
public void setValue(Object value) {
	if (value instanceof MultipartFile) {
		MultipartFile multipartFile = (MultipartFile) value;
		try {
			super.setValue(this.charsetName != null ?
					new String(multipartFile.getBytes(), this.charsetName) :
					new String(multipartFile.getBytes()));
		}
		catch (IOException ex) {
			throw new IllegalArgumentException("Cannot read contents of multipart file", ex);
		}
	}
	else {
		super.setValue(value);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:StringMultipartFileEditor.java

示例8: setValue

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@Override
public void setValue(Object value) {
	if (value instanceof MultipartFile) {
		MultipartFile multipartFile = (MultipartFile) value;
		try {
			super.setValue(multipartFile.getBytes());
		}
		catch (IOException ex) {
			throw new IllegalArgumentException("Cannot read contents of multipart file", ex);
		}
	}
	else if (value instanceof byte[]) {
		super.setValue(value);
	}
	else {
		super.setValue(value != null ? value.toString().getBytes() : null);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:ByteArrayMultipartFileEditor.java

示例9: saveImage

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * Saves an image in the database.
 *
 * @param name      The filename of the image, including type.
 * @param file      The file to be saved.
 * @param path      The special path that ties an event to an image.
 * @param type      The mimetype of the image.
 * @return          A boolean that indicates whether the saving was successful.
 */
@Override
public boolean saveImage(String name, MultipartFile file, String path, String type) {
    byte[] imageByteArray;

    try {
        imageByteArray = file.getBytes();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

    Image image = new Image(name, imageByteArray, path, type);
    MongoCollection collection = client.getClient().getCollection("images");
    collection.insert(image);

    return true;
}
 
开发者ID:2DV603NordVisaProject,项目名称:nordvisa_calendar,代码行数:27,代码来源:ImageDAOMongo.java

示例10: uploadFile

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public boolean uploadFile(Picture picture, MultipartFile file) {

        if (!file.isEmpty())
            try {
                byte[] bytes = file.getBytes();
                File dir = new File(picture.getPath());
                if (!dir.exists())
                    dir.mkdirs();

                File serverFile = new File(dir.getAbsolutePath() + "\\" + picture.getName() + picture.getFileType());
                BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));

                stream.write(bytes);
                stream.close();
                return true;
            } catch (Exception e) {
                return false;
            }

        return false;
    }
 
开发者ID:xSzymo,项目名称:Spring-web-shop-project,代码行数:22,代码来源:PictureOperations.java

示例11: upload

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * 文件上传
 * @param file Spring的MultipartFile类
 * @param mediaType 文件类型。e.g. picture, video..
 * @param module 模块。e.g. employee, user, department..
 * @return 图片上传位置的相对路径。相对于url.properties配置文件的url.upload值
 * @throws java.io.IOException
 */
public String upload(MultipartFile file, String mediaType, String module) throws IOException {
    //设置文件存放位置
    String uploadUrl = env.getProperty("url.upload");
    if (uploadUrl == null || uploadUrl.equals("")) {
        uploadUrl = webAppAbsUrl + "Upload/";
    }

    if (file == null || file.isEmpty()) {
        return null;
    }
    byte[] bytes = file.getBytes();
    String[] nameArr = file.getOriginalFilename().split("\\.");
    String fileType = nameArr[nameArr.length-1];
    SimpleDateFormat dateFormat = new SimpleDateFormat("/yyyy/MM/dd/");
    String dir = dateFormat.format(new Date());
    String fileName = System.currentTimeMillis() + "." + fileType;
    // 文件的相对路径名
    String relUrl = mediaType + "/" + module + dir + fileName;
    // 文件的绝对路径名
    String absUrl = uploadUrl + "/" + relUrl;

    File path = new File(uploadUrl + "/" + mediaType + "/" + module + dir);
    if (!path.exists()) {
        path.mkdirs();
    }
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(absUrl));
    out.write(bytes);
    out.flush();
    out.close();

    return relUrl;
}
 
开发者ID:jthinking,项目名称:image-server,代码行数:41,代码来源:UploadService.java

示例12: toDSSDocument

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public static DSSDocument toDSSDocument(MultipartFile multipartFile) {
	try {
		if ((multipartFile != null) && !multipartFile.isEmpty()) {
			DSSDocument document = new InMemoryDocument(multipartFile.getBytes(), multipartFile.getOriginalFilename());
			return document;
		}
	} catch (IOException e) {
		logger.error("Cannot read  file : " + e.getMessage(), e);
	}
	return null;
}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:12,代码来源:WebAppUtils.java

示例13: uploadCamera

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@RequestMapping(value = ENDPOINT_ROINT + "/{name}", method = RequestMethod.POST)
@PreAuthorize(BotApiApplication.HAS_AUTH_ROLE_ORCHESTRATOR)
public @ResponseBody Long uploadCamera(@RequestParam("file") MultipartFile file, @PathVariable("name") final String name) throws IOException {
    BotCamera botCam = new BotCamera(file.getBytes(), new Date());
    PlayerBot playerBot = playerBotRepository.findByName(name);

    botCam.setPlayerBot(playerBot);

    botCam = botCameraRepository.save(botCam);
    return botCam.getId();
}
 
开发者ID:corydissinger,项目名称:mtgo-best-bot,代码行数:12,代码来源:BotCameraController.java

示例14: store

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * 如果图片的大小大于1M,那么进行等比压缩为1280x1280图片
 * @param file
 * @return
 * @throws Exception
 */
public Storage store(MultipartFile file) throws Exception {

    if (file.isEmpty()) {
        throw new Exception("Failed to store empty file " + file.getOriginalFilename());
    }

    String fileType = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
    byte[] bytes;
    // 如果原图片大于1M, 那么压缩图片
    if (file.getSize() > M) {
        bytes = ImageUtil.compress(file.getInputStream(), fileType, 1920, 1920);
    } else {
        bytes = file.getBytes();
    }

    String contentHash = DigestUtils.md5DigestAsHex(bytes);
    Storage oldStorage = storageRepository.findByFileHash(contentHash);
    if (oldStorage != null) return oldStorage;

    try {
        Path destDir = Paths.get(storageDirectory, contentHash.substring(0, 2));
        if (!Files.exists(destDir)) Files.createDirectory(destDir);

        // String filePath = contentHash.substring(0, 2) + "/" + contentHash.substring(2) + "." + fileType;
        Storage storage = new Storage();
        storage.setFileHash(contentHash);
        storage.setFileName(file.getName());
        storage.setFileType(file.getContentType());
        storage.setFileSize(file.getSize());
        storage.setOriginalFileName(file.getOriginalFilename());

        return storageRepository.save(storage);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }

}
 
开发者ID:myliang,项目名称:fish-admin,代码行数:45,代码来源:StorageService.java

示例15: addCrousCsvFile

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@RequestMapping(value = "/addCrousCsvFile", method = RequestMethod.POST, produces = "text/html")
public String addCrousCsvFile(MultipartFile file, @RequestParam(defaultValue="False") Boolean inverseCsn) throws IOException, ParseException {
	
	if(file != null) {
		String filename = file.getOriginalFilename();
		log.info("CrousSmartCardController retrieving file " + filename);
		InputStream stream = new  ByteArrayInputStream(file.getBytes());
		crousSmartCardService.consumeCsv(stream, inverseCsn);
	}

	return "redirect:/admin/crouscards";
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:13,代码来源:CrousSmartCardController.java


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