Can anyone please explain how the Spring's Multipartfile works?
up vote
1
down vote
favorite
i've been trying to understand how the multipartfile works in spring
but did't find out any helpful info on internet.
Trying to understand this method:
public String copyUploadedImage(MultipartFile multipartFile, String realpath, int userId) throws IOException {
String orgFileName = null;
orgFileName = multipartFile.getOriginalFilename();
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
if (multipartFile.getSize() > 0) {
inputStream = multipartFile.getInputStream();
String root = realpath + File.separator + userId + File.separator + "Image" + File.separator;
File file = new File(root + File.separator);
if (file.mkdirs()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
}
fileName = file + File.separator + multipartFile.getOriginalFilename();
outputStream = new FileOutputStream(fileName);
int readBytes = 0;
byte buffer = new byte[10000];
while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) {
outputStream.write(buffer, 0, readBytes);
}
outputStream.flush();
outputStream.close();
inputStream.close();
}
return orgFileName;
}
java spring-mvc
|
show 2 more comments
up vote
1
down vote
favorite
i've been trying to understand how the multipartfile works in spring
but did't find out any helpful info on internet.
Trying to understand this method:
public String copyUploadedImage(MultipartFile multipartFile, String realpath, int userId) throws IOException {
String orgFileName = null;
orgFileName = multipartFile.getOriginalFilename();
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
if (multipartFile.getSize() > 0) {
inputStream = multipartFile.getInputStream();
String root = realpath + File.separator + userId + File.separator + "Image" + File.separator;
File file = new File(root + File.separator);
if (file.mkdirs()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
}
fileName = file + File.separator + multipartFile.getOriginalFilename();
outputStream = new FileOutputStream(fileName);
int readBytes = 0;
byte buffer = new byte[10000];
while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) {
outputStream.write(buffer, 0, readBytes);
}
outputStream.flush();
outputStream.close();
inputStream.close();
}
return orgFileName;
}
java spring-mvc
What exactly do you want to know? How MultipartFile works or what the method is doing (short answer: it saves an uploaded (image) file in a directory based on the givenrealpath
anduserId
parameters)?
– quatax
Nov 20 at 5:50
@quatax thanks for response. I know why it is used in applications but i just want to know how it works internally to store a file into DB.
– SHAIK BAJI VALI
Nov 20 at 6:24
The file isn't stored in a database in this method. It gets written to the file system.
– quatax
Nov 20 at 6:28
@quatax ,ok but how it actually works internally?
– SHAIK BAJI VALI
Nov 20 at 6:32
So, you want to know how Java writes Bytes to the file system?
– quatax
Nov 20 at 6:42
|
show 2 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
i've been trying to understand how the multipartfile works in spring
but did't find out any helpful info on internet.
Trying to understand this method:
public String copyUploadedImage(MultipartFile multipartFile, String realpath, int userId) throws IOException {
String orgFileName = null;
orgFileName = multipartFile.getOriginalFilename();
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
if (multipartFile.getSize() > 0) {
inputStream = multipartFile.getInputStream();
String root = realpath + File.separator + userId + File.separator + "Image" + File.separator;
File file = new File(root + File.separator);
if (file.mkdirs()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
}
fileName = file + File.separator + multipartFile.getOriginalFilename();
outputStream = new FileOutputStream(fileName);
int readBytes = 0;
byte buffer = new byte[10000];
while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) {
outputStream.write(buffer, 0, readBytes);
}
outputStream.flush();
outputStream.close();
inputStream.close();
}
return orgFileName;
}
java spring-mvc
i've been trying to understand how the multipartfile works in spring
but did't find out any helpful info on internet.
Trying to understand this method:
public String copyUploadedImage(MultipartFile multipartFile, String realpath, int userId) throws IOException {
String orgFileName = null;
orgFileName = multipartFile.getOriginalFilename();
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
if (multipartFile.getSize() > 0) {
inputStream = multipartFile.getInputStream();
String root = realpath + File.separator + userId + File.separator + "Image" + File.separator;
File file = new File(root + File.separator);
if (file.mkdirs()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
}
fileName = file + File.separator + multipartFile.getOriginalFilename();
outputStream = new FileOutputStream(fileName);
int readBytes = 0;
byte buffer = new byte[10000];
while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) {
outputStream.write(buffer, 0, readBytes);
}
outputStream.flush();
outputStream.close();
inputStream.close();
}
return orgFileName;
}
java spring-mvc
java spring-mvc
asked Nov 20 at 3:58
SHAIK BAJI VALI
316
316
What exactly do you want to know? How MultipartFile works or what the method is doing (short answer: it saves an uploaded (image) file in a directory based on the givenrealpath
anduserId
parameters)?
– quatax
Nov 20 at 5:50
@quatax thanks for response. I know why it is used in applications but i just want to know how it works internally to store a file into DB.
– SHAIK BAJI VALI
Nov 20 at 6:24
The file isn't stored in a database in this method. It gets written to the file system.
– quatax
Nov 20 at 6:28
@quatax ,ok but how it actually works internally?
– SHAIK BAJI VALI
Nov 20 at 6:32
So, you want to know how Java writes Bytes to the file system?
– quatax
Nov 20 at 6:42
|
show 2 more comments
What exactly do you want to know? How MultipartFile works or what the method is doing (short answer: it saves an uploaded (image) file in a directory based on the givenrealpath
anduserId
parameters)?
– quatax
Nov 20 at 5:50
@quatax thanks for response. I know why it is used in applications but i just want to know how it works internally to store a file into DB.
– SHAIK BAJI VALI
Nov 20 at 6:24
The file isn't stored in a database in this method. It gets written to the file system.
– quatax
Nov 20 at 6:28
@quatax ,ok but how it actually works internally?
– SHAIK BAJI VALI
Nov 20 at 6:32
So, you want to know how Java writes Bytes to the file system?
– quatax
Nov 20 at 6:42
What exactly do you want to know? How MultipartFile works or what the method is doing (short answer: it saves an uploaded (image) file in a directory based on the given
realpath
and userId
parameters)?– quatax
Nov 20 at 5:50
What exactly do you want to know? How MultipartFile works or what the method is doing (short answer: it saves an uploaded (image) file in a directory based on the given
realpath
and userId
parameters)?– quatax
Nov 20 at 5:50
@quatax thanks for response. I know why it is used in applications but i just want to know how it works internally to store a file into DB.
– SHAIK BAJI VALI
Nov 20 at 6:24
@quatax thanks for response. I know why it is used in applications but i just want to know how it works internally to store a file into DB.
– SHAIK BAJI VALI
Nov 20 at 6:24
The file isn't stored in a database in this method. It gets written to the file system.
– quatax
Nov 20 at 6:28
The file isn't stored in a database in this method. It gets written to the file system.
– quatax
Nov 20 at 6:28
@quatax ,ok but how it actually works internally?
– SHAIK BAJI VALI
Nov 20 at 6:32
@quatax ,ok but how it actually works internally?
– SHAIK BAJI VALI
Nov 20 at 6:32
So, you want to know how Java writes Bytes to the file system?
– quatax
Nov 20 at 6:42
So, you want to know how Java writes Bytes to the file system?
– quatax
Nov 20 at 6:42
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386007%2fcan-anyone-please-explain-how-the-springs-multipartfile-works%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What exactly do you want to know? How MultipartFile works or what the method is doing (short answer: it saves an uploaded (image) file in a directory based on the given
realpath
anduserId
parameters)?– quatax
Nov 20 at 5:50
@quatax thanks for response. I know why it is used in applications but i just want to know how it works internally to store a file into DB.
– SHAIK BAJI VALI
Nov 20 at 6:24
The file isn't stored in a database in this method. It gets written to the file system.
– quatax
Nov 20 at 6:28
@quatax ,ok but how it actually works internally?
– SHAIK BAJI VALI
Nov 20 at 6:32
So, you want to know how Java writes Bytes to the file system?
– quatax
Nov 20 at 6:42