BuddyBuild and gradle.properties in Android apps

People advise against storing keys inside build.gradles. We should store them on 1Password and populate our gradle.properties, so don't track this file in git. Here is .gitignore file But when…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to Upload a .csv file and Post its data to an External REST API using Laravel 8.x

Recently I was faced with a task to post data from a .csv file to an external REST API. I’m just going to log in to this article about what I did to get the job done.

Let’s start by creating a template for uploading the file. For this article’s sake, lets make the changes in the dashboard.blade.php file.

Note : Don’t forget to add enctype=”multipart/form-data”!

Once the user has submitted the file, we need a new router to process the file and send its content to the REST API. Let’s start by creating a Controller.

Now in the web.php file,

In the UploadController.php , create a function named upload. We will be writing all the code inside this function. Also, we need an action for the form.

Now inside the upload function, we need to get the submitted file and parse its contents.

Get the submitted file,

Parse the submitted file,

Keeping this in mind, we will create a sample .csv template to be submitted. The fields need to be two, namely Name and Job.

We need to send the values from this file as the request body to the API. So let’s add the code to loop through the content of this file.

This will create each student for each row of the file. But we don’t need to send the data of the first row of the file.

Full code:

This will post the data starting from the second row of the file, display a success message once the users are created, and an error message if the submit button is clicked without choosing a file.

Full template:

That’s it, thanks for reading :)

Add a comment

Related posts:

Chasing Venture Capital Experience

Financial success in venture capital is based on experience and of course the hand of fate in combination with great timing. Nonetheless, without in-depth experience you might be better off spending…

Simple Tips for a Better Sleep

I remember reading some early research on scientists studying insomniacs. In one innovative model, a scientist hypothesised that the main challenge for many people was that their bodies had forgotten…

Proyeksi Penduduk dengan Metode Cohort Analysis

Analisis Cohort merupakan salah satu metode yang digunakan untuk memproyeksikan jumlah penduduk dimasa yang akan datang. Analisis Cohort mengacu pada perubahan-perubahan komponen penduduk yaitu…