Home > Back-end >  Upload File MultipartFile class into the File without the use of temporary files
Upload File MultipartFile class into the File without the use of temporary files

Time:09-16

CommonsMultipartFile cf=(CommonsMultipartFile) file;
DiskFileItem fi=(DiskFileItem) cf. GetFileItem ();
The File f=fi. GetStoreLocation ();
The above method can convert MultipartFile type to the File type File, but the converted File is a temporary File temp type computer, is not convenient to operate, is there any method can transform method without temporary files

CodePudding user response:

CodePudding user response:

File file=new File(path);
FileUtils. CopyInputStreamToFile (multipartFile. GetInputStream (), the file).

CodePudding user response:

refer to the second floor seven plus one I reply:
File File=new File (path);
FileUtils. CopyInputStreamToFile (multipartFile. GetInputStream (), the file).
I think you are drunk

CodePudding user response:

Is generally not upload file is downloaded, in addition to the form of what need to deal with, you can use the flow in the form of a
Don't know you have to use, put one uploaded!
Public static void uploadFile (byte [] file, String filePath, String fileName) throws the Exception {
The File targetFile=new File (filePath);
if (! TargetFile. The exists ()) {
TargetFile. The file.mkdirs ();
}
FileOutputStream out=new FileOutputStream (filePath + fileName);
Out. Write (file);
out.flush();
out.close();
}

CodePudding user response:

FileUtil. UploadFile (file. GetBytes (), fileBasePath + filePath, fileName);

CodePudding user response:

reference BlackMirrorD reply: 3/f
Quote: refer to the second floor seven plus one I reply:

File file=new File(path);
FileUtils. CopyInputStreamToFile (multipartFile. GetInputStream (), the file).
I think you are drunk

But that's how I used

CodePudding user response:

The
Quote: refer to his reply:

[/quote that I do, what are you doing new File]

CodePudding user response:

references a 3-yellow 4 floor response:
is generally not upload file is downloaded, in addition to the form of what need to deal with, you can use the flow in the form of a
Don't know you have to use, put one uploaded!
Public static void uploadFile (byte [] file, String filePath, String fileName) throws the Exception {
The File targetFile=new File (filePath);
if (! TargetFile. The exists ()) {
TargetFile. The file.mkdirs ();
}
FileOutputStream out=new FileOutputStream (filePath + fileName);
Out. Write (file);
out.flush();
out.close();
}


refer to 7th floor BlackMirrorD response:
Quote: refer to his reply:

[/quote that I do, what are you doing new File]
File (filePath);
if (! TargetFile. The exists ()) {
TargetFile. The file.mkdirs ();
}
FileOutputStream out=new Fi

refer to 7th floor BlackMirrorD response:
Quote: refer to his reply:

[/quote that I do, what are you doing new File]

The File (filePath);
if (! TargetFile. The exists ()) {
TargetFile. The file.mkdirs ();
}
FileOutputStream out=new Fi

CodePudding user response:

refer to the eighth floor of low-level siege lion response:
Quote: a reference 4 floor 3-yellow response:
is generally not upload file is downloaded, in addition to the form of what need to deal with, you can use the flow in the form of a
Don't know you have to use, put one uploaded!
Public static void uploadFile (byte [] file, String filePath, String fileName) throws the Exception {
The File targetFile=new File (filePath);
if (! TargetFile. The exists ()) {
TargetFile. The file.mkdirs ();
}
FileOutputStream out=new FileOutputStream (filePath + fileName);
Out. Write (file);
out.flush();
out.close();
}






  • Related