forked from rongchao/epmet-cloud-rizhao
				
			
				 5 changed files with 120 additions and 7 deletions
			
			
		| @ -0,0 +1,64 @@ | |||||
|  | package com.epmet.util; | ||||
|  | 
 | ||||
|  | import org.springframework.web.multipart.MultipartFile; | ||||
|  | 
 | ||||
|  | import java.io.*; | ||||
|  | 
 | ||||
|  | public class ConvertToMultipartFile implements MultipartFile { | ||||
|  |     private byte[] fileBytes; | ||||
|  |     String name; | ||||
|  |     String originalFilename; | ||||
|  |     String contentType; | ||||
|  |     boolean isEmpty; | ||||
|  |     long size; | ||||
|  | 
 | ||||
|  |     public ConvertToMultipartFile(byte[] fileBytes, String name, String originalFilename, String contentType, | ||||
|  |                                   long size) { | ||||
|  |         this.fileBytes = fileBytes; | ||||
|  |         this.name = name; | ||||
|  |         this.originalFilename = originalFilename; | ||||
|  |         this.contentType = contentType; | ||||
|  |         this.size = size; | ||||
|  |         this.isEmpty = false; | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public String getName() { | ||||
|  |         return name; | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public String getOriginalFilename() { | ||||
|  |         return originalFilename; | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public String getContentType() { | ||||
|  |         return contentType; | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public boolean isEmpty() { | ||||
|  |         return isEmpty; | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public long getSize() { | ||||
|  |         return size; | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public byte[] getBytes() throws IOException { | ||||
|  |         return fileBytes; | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public InputStream getInputStream() throws IOException { | ||||
|  |         return new ByteArrayInputStream(fileBytes); | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     @Override | ||||
|  |     public void transferTo(File dest) throws IOException, IllegalStateException { | ||||
|  |         new FileOutputStream(dest).write(fileBytes); | ||||
|  |     } | ||||
|  | } | ||||
					Loading…
					
					
				
		Reference in new issue