File Upload and Download with Spring Boot - REST API

File Upload and Download with Spring Boot - REST API

Daily Code Buffer

2 года назад

68,967 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Rajesh Chauhan
Rajesh Chauhan - 04.11.2023 20:10

Same thing can you done without rest controller use JSP page please reply how can we do this with Excel sheet download and data show in JSP from db

Ответить
Madhumitha S
Madhumitha S - 26.10.2023 07:58

Hii bro could you please tell me that the file upload can be using seperate package or can be used with the application please reply

Ответить
vishal kumar
vishal kumar - 05.09.2023 14:08

Hi Shabir you are awesome I went through all the video which you shared and got better understanding earlier I was not aware of microservice and spring boot as well but after going through your video on these now have good hands on this thank you so much for making this wonderful session keep it up 🙂👍

Ответить
Fluttertrends
Fluttertrends - 04.09.2023 15:23

For who wants to view/get without downloading:
@PostMapping("/upload")
public ResponseData uploadFile(@RequestParam("file") MultipartFile file) throws Exception {
Attachment attachment = null;
String downloadUrl = "";
String viewUrl = "";
attachment = attachmentService.saveAttachment(file);
downloadUrl = ServletUriComponentsBuilder.fromCurrentContextPath()
.path("/download/")
.path(attachment.getId())
.toUriString();
viewUrl = ServletUriComponentsBuilder.fromCurrentContextPath()
.path("/view/")
.path(attachment.getId())
.toUriString();

return new ResponseData(attachment.getFileName(), downloadUrl, viewUrl, file.getContentType(), file.getSize());
}

@GetMapping("/view/{fileId}")
public ResponseEntity<Resource> viewFile(@PathVariable String fileId) throws Exception {
Attachment attachment = attachmentService.getAttachment(fileId);
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(attachment.getFileType()))
.body(new ByteArrayResource(attachment.getData()));
}



And the response data add the private String viewUrl;
public class ResponseData {

private String fileName;
private String downloadUrl;
private String viewUrl;
private String fileType;
private Long fileSize;
}

Ответить
PRASHANTH GOLLA
PRASHANTH GOLLA - 17.08.2023 15:54

how to send form data ,request body and store them in DB using spring boot rest api

Ответить
humayun kabir
humayun kabir - 01.08.2023 05:51

make a video for scanning website uri for file download

Ответить
Anwesh Abhisek
Anwesh Abhisek - 12.07.2023 15:26

Not working at the end . Pls help me

Ответить
Venkatesh Raju
Venkatesh Raju - 12.07.2023 08:34

there was occuring 406 error, any one can help?

Ответить
Rustem Zamaliev
Rustem Zamaliev - 08.07.2023 02:01

Great tutorial! Thanks for this. However I have question. Ha to download several images from server? I’ve already broken my brain trying to understand how to do this, and I got nowhere

Ответить
Subham Raoniar
Subham Raoniar - 19.06.2023 03:47

Nice video. Tips for new viewers, if you're using latest spring boot version and MySQL then change the dialect property to org.hibernate.dialect.MySQLDialect and in the Attachment class above the data field add this annotation @Column(name="data", columnDefinition = "LONGBLOB".
Then there will be no error. 😊

Ответить
Ibra Co
Ibra Co - 21.05.2023 07:27

First of all I want to congratulate you for the brilliant work! Second, I would like to know if this demonstration of yours is valid (if it serves) for types of files that are in pdf format, mp4 (video format) etc...?

Ответить
medzied haddar
medzied haddar - 17.05.2023 11:11

Thank you <3

Ответить
yimin zhou
yimin zhou - 05.04.2023 08:00

when i use the download API, It says "Sorry, Photos can not open this file because the format is currently unsupported, or the file is corrupted"
Please help

Ответить
janne matti Lindenau
janne matti Lindenau - 16.02.2023 22:20

Nice Video! For usual I habe problems understanding indish accent, but not here!

Ответить
Elkhan Ismayilov
Elkhan Ismayilov - 20.01.2023 09:48

Man everything is okay? fine but one problem how we can delete a file in multipart file???? can you answer me?

Ответить
ibra11 3
ibra11 3 - 30.12.2022 05:25

I coded this in Kotlin and it worked fine, but when I upload a PDF, the generated URL doesn't download the PDF file. It just opens it on the web. Any thoughts?

Ответить
Danilo Samardzic
Danilo Samardzic - 30.11.2022 17:45

why you send one parameter file, i need more parameter and how to upload image :D

Ответить
Diego Colonia
Diego Colonia - 18.11.2022 09:32

after watching many tutorial, this was the one who worked for me, THANKS

Ответить
Bekjan Satiev
Bekjan Satiev - 26.10.2022 19:31

OMG you're my savior. THANK YOU soooo MUCH!!!!

Ответить
Sana
Sana - 29.09.2022 14:08

i am getting this while testing upload api == Method Not Allowed

Ответить
youssoupha faye
youssoupha faye - 27.09.2022 13:09

hello, great video thank you for your work . where is the video for saving the file in system and save path only because database are mainly not for saving file

Ответить
Praveen
Praveen - 18.09.2022 06:22

bro can you add functionality of awsTextract in this video

Ответить
balakrishna m
balakrishna m - 31.08.2022 15:12

Can you please do one video on mutiple files for mutliple fields and json using react and spring boot.

Ответить
balakrishna m
balakrishna m - 31.08.2022 15:09

This is very good video...

Ответить
Shailesh Kumar
Shailesh Kumar - 10.08.2022 09:13

Good

Ответить
prashant kumar
prashant kumar - 03.08.2022 15:58

Thanks for such informative and helpful content.

Ответить
ado no
ado no - 30.07.2022 13:42

Hey Bro. Your intellij idea looks beautiful. What theme are you using? And the video was very important to me.

Ответить
Sharmila Mohanraj
Sharmila Mohanraj - 20.07.2022 10:26

hi, can you please guide on how to convert this file data fetched to readable json format?

Ответить
Ravi Gupta
Ravi Gupta - 08.07.2022 11:27

Hi can you make a video on how authentication and authorisation work in api-gateway

Ответить
Faiz Quazi
Faiz Quazi - 27.06.2022 14:50

Bro Thanks a lot for this session! When I was following your steps I came across Dialect org.hibernate.dialect.MySQL5DialectInnoDBDialect was not supporting in my system so i changed it to org.hibernate.dialect.MySQL5Dialect but was getting below error while creation of the table

java.sql.SQLSyntaxErrorException: Specified key was too long; max key length is 1000 bytes/ fix using mysql workbench

Can u please help to see alternatives for this?

Ответить
Mateus WDO
Mateus WDO - 26.06.2022 00:07

nice tutorial

Ответить
BOUABDELLAH SAID ABDELDJALIL
BOUABDELLAH SAID ABDELDJALIL - 24.06.2022 02:47

why it isnt working for me ? it s directly throwing the exception which is saying could not save file: filename !! But why ?

Ответить
Sheen Raina
Sheen Raina - 15.06.2022 20:10

Can u pls make similar video almost as to how upload download files using azure blob storage using rest api. Also how to upload and download by not using postman , directly from code ( template UI)

Ответить
Anvarbek Turdaliyev
Anvarbek Turdaliyev - 11.06.2022 09:48

Thank you

Ответить
Ipseeta Jena
Ipseeta Jena - 09.06.2022 11:13

Can you tell about pharmacy management project using spring boot

Ответить
Arjun Patel
Arjun Patel - 22.04.2022 11:27

Can you please create a video on spring batch framework.

Ответить
Learn
Learn - 06.04.2022 12:06

Bro what is the theme you are using for intellij? please say the name

Ответить
ainigma100
ainigma100 - 04.04.2022 20:10

Thank you for your video! I have a question regarding file upload. Maybe someone tries to upload a malicious file. Is there a way to scan the file before we process it? Maybe there is some kind of Java API which could be used to scan the file

Ответить
Raj
Raj - 01.04.2022 12:18

what is propose of creating entity and model within different package?

Ответить
Jesús Tapia
Jesús Tapia - 30.03.2022 10:00

Thanks for the video, it is so useful

Ответить
Robin Rao
Robin Rao - 27.03.2022 05:14

Hey buddy a small suggestion though. We do not require so many class files just for upload and download. Everything can be done within 3 classes , A repository interface, an entity class, and a Controller. That's all. It's super simple and easy to maintain. At max we would require a DAO file. But not anymore than this

Ответить
Lalit k
Lalit k - 26.03.2022 17:12

Great 👍👍👍

Ответить
Scoty98
Scoty98 - 26.03.2022 15:51

Great tutorial bro 🔥. Do you plain smth about „Spring boot testing Full in Depth”, will be great 🙉🚀

Ответить
Prajwal Shakya
Prajwal Shakya - 26.03.2022 11:40

Great work bro..your video has been very helpful

Ответить
Adedamola Adegoke
Adedamola Adegoke - 24.03.2022 18:26

Thank you as always nabbir, i was able to code along, and also used ServletUriComponentsBuilder.fromCurrentRequest when i was getting error with .fromContext. either way i need to study and really understand how it all works. Thanks for the video.

Ответить