Answer the question
In order to leave comments, you need to log in
How to save and upload pictures to google drive?
Here is the code that does this locally. Please tell me where you can read about this and what is needed for this?
public void addNews(News news, MultipartFile image) {
final String name = image.getOriginalFilename();
final String location = "E://pictures//";
FileEntity fileEntity = new FileEntity();
try {
if (image.getSize() > 0 && image.getInputStream() != null && name != null) {
final Path outputFile = Paths.get(location, name);
fileEntity.setLocation(location);
fileEntity.setFileName(name);
news.setFileEntity(fileEntity);
fileEntity.setNews(news);
try (final ReadableByteChannel input = Channels.newChannel(image.getInputStream());
final WritableByteChannel output = Channels.newChannel(new FileOutputStream(outputFile.toFile()))) {
final ByteBuffer buffer = ByteBuffer.allocate(1024);
while (input.read(buffer) >= 0 || buffer.position() > 0) {
buffer.flip();
output.write(buffer);
buffer.compact();
}
}
}
} catch (IOException e) {
logger.error(e.getMessage());
}
newsDao.saveOrUpData(news);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question