Flutter : Upload file / pdf / audio in your app | multipart request | flutter coding

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this vlog we will try to upload multiple  files so here you can see the files like a folder   sample pdf file and also an audio file   so we are trying to upload all these files  to server from our flutter application so if you have gone through our previous tutorial  we have uploaded an image to our server and   also we have seen the step by step tutorial  of how to upload an image to our server   so in the continuation of our previous tutorial in  this vlog we will try to upload few files and now   you need to specify these files in pubspec so  what i have done is like i have just added the   assets folder and it will consider all the files  available in the assets folder and you need not   specify individually so now let's get started  with the tutorial i suggest you to go through   our previous tutorial because i'm using the same  code here and i have explained the code over there   and here i'm just considering a method  upload image here so now let's try to make it   upload files and here we don't require any  parameter and so i'm removing this title as well   and also change this method to upload files and  which is an asynchronous method here why because   we need to wait till the file is loaded and  also we need to wait till the file is being   uploaded and we fetch the response so we  required an asynchronous method here so   the asynchronous method will process the data in  background and provide the output once it receives   and also it's a better practice to use  asynchronous method so here you can see   we have provided a multipart request and here  i have provided a url here so provide your   url over here and also specify the method  to be post and these are our parameters and these two are the parameters so generally  we have specified audio and file here instead   you can just specify audio file name so here  you can specify the name of your audio file   and here you can just specify data regarding it  like date created and you can just specify date   here and also these are the header sections where  you can provide your authorization in previous   tutorial we have provided an authorization so  for some specific urls there needs to be some   security patterns implemented only the person who  have the particular authentication can upload the   data so in this scenario you can make use of the  header section and upload them so what if there   are multiple headers here you can just make use  of a map which is of a type string comma string   here and you can name it as headers and here we  are going to add multiple headers here so this   is our first header and this is a key and value  separated by a semicolon here so if you are having   multiple headers you can just specify in this way  and make sure you provide a semicolon between the   key and value of a header so now let us consider  the first parameter to be authorization and here   you can just specify your authorization code and  let's consider the another one to be a client id   so here you can just specify your client id i'm  just providing some dummy details here in real   time you can add the details accordingly and now  we need to make use of this map headers here like   headers dot add all and here you can  just specify the headers and in this   way you can add multiple headers  here so this is the header section and also we are not passing our files in the  parameters here instead we are making use of   a multi-part file here and here you can see i  have already provided audio file here test and   also a new folder which is of a compressor type  so here you can see the format dot zip and now   let's try to add one more file here so we have  also we also have a pdf file so assets sample dot   pdf so one thing you can notice here we  have specifying file name also here itself   so in the parameters also i have tried to provide  the file name and it's again your wish you may   provide it in parameters or over here but to  make sure the options available i'm just trying   to explain you in this scenario no let's try to  provide it as sample dot pdf so these are all the   files here audio file and pdf and now let's try  to add the pdf also here file start add pdf so we   have added all the three files here audio file and  pdf and now we are trying to fetch the so this is   our response section and once we get the response  here we are trying to provide the output here so i   think you are clear so far and i suggest you to  go through our previous tutorial also you get a   good idea on what we are trying to do here and now  let's try to run this code and see the output here   so now whenever you tap on the upload button log  visible so when you tap on the upload button you   can see we are getting a response after some time  why because in this particular time your files are   being uploaded to the server and waiting for the  response and once we got the response then it is   successfully displayed here so using the print  statement here we are able to print the response   here so i hope you understood this tutorial and  the code for this tutorial is also provided in the   description section below so you may go and visit  them in our channel and if you wanted to know any   other tutorials you can also do let me know in the  comment section below i will try to help you with   them and for more interesting tutorials on flutter  do like share and subscribe to our channel for   more interesting content and we have also provided  various tutorials on flutter beginner level
Info
Channel: amplifyabhi coding
Views: 17,571
Rating: undefined out of 5
Keywords:
Id: FZmjLZOkQwk
Channel Id: undefined
Length: 7min 31sec (451 seconds)
Published: Wed Sep 08 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.