Google Apps Script Tutorial to Download Images From URL to Sheets Rows Cells & Google Drive Folder
Dec 21, 2025
Buy the full source code of application here in USD at paypal here:
https://procodestore.com/index.php/product/google-apps-script-tutorial-to-download-images-from-url-to-sheets-rows-cells-google-drive-folder/
Show More Show Less View Video Transcript
0:00
Uh hello friends, today in this tutorial
0:02
I will be showing you that how basically
0:04
we can download images from the URL
0:06
inside our Google sheets and we can
0:09
insert the images right here physical
0:11
images. So basically this is the URL of
0:13
the images which are there from the
0:15
internet unsplash pixabay you can just
0:17
copy paste the URLs of these inside your
0:20
Google sheet and basically I will be
0:22
showing you a simple Google app script
0:24
which will actually download the images
0:26
from these URLs one by one. Let me show
0:29
you this animation here. So you can see
0:31
we have two functions written here.
0:32
Insert images. First of all, it will
0:34
insert these images inside this Google
0:36
sheet. This columns images will be
0:39
present here. And after this, we will
0:41
also be uploading these images directly
0:43
guys from the URL that you see right
0:45
here from the Google sheet to directly
0:47
to our Google Drive. You can see we have
0:50
created a images folder here. So inside
0:52
our Google Drive. So all these images
0:54
will be directly published here inside
0:56
Google Drive. uploaded here from the
0:58
URL. So let me first of all insert these
1:01
images inside this Google sheet guys. So
1:03
many a times you want the images to be
1:05
present inside your Google sheet. So we
1:07
have written a simple function insert
1:09
image. Let me run this function. So let
1:10
me select this function and click on the
1:12
run button. So as I click run button
1:14
guys you can see that one by one it will
1:16
take the URL and it will download these
1:18
images right here inside the column
1:20
itself. You can see one by one. So you
1:22
can see a total of six images have been
1:25
successfully downloaded. And basically
1:27
you can see this is the image right
1:29
here.
1:30
If you see uh you can even
1:34
enlarge it and also see here this is a
1:36
physical image guys. You can see that
1:38
basically the images are there inside
1:41
the cells of the Google sheet. And now
1:44
guys if you want to directly download
1:46
them inside our Google drive basically
1:48
you need to download these images inside
1:51
your Google drive. There is a second
1:53
function which we have written which is
1:54
a download image function. Let me run
1:56
this function now and click on the run
1:58
button. So as I click on run button guys
2:00
you can see one by one the images will
2:02
be downloaded to your Google drive. Just
2:04
wait here one by one. You will see 1 2
2:07
and uh 3 4 5 6 a total of six images
2:11
have been successfully downloaded. You
2:13
can see that guys 1 2 3 4 5 6. So these
2:16
are the two utility kind of Google app
2:18
script we will be writing in this
2:20
tutorial which will let you download the
2:22
images from a URL from the internet
2:24
directly to your Google drive and to
2:26
your Google sheet inside your cells rows
2:29
and columns. So first of all guys I will
2:31
start from scratch. So you need to first
2:35
of all if you want to the full source
2:37
code of this tutorial you can just go to
2:39
the description of this video. I have
2:40
written a complete blog post,
2:41
step-by-step blog post explaining each
2:44
instruction in detail. So I will highly
2:46
recommend that you go to this blog post
2:48
and uh alongside with watching this
2:50
video, you can read this blog post. So
2:52
let's start building this project. So
2:54
first of all guys, what we need to do is
2:56
that we need to create a new sheet. So
2:58
you just need to go to Google sheet and
3:00
click on go to sheets and you need to
3:02
create a blank sheet out there. And
3:04
basically here you can rename this sheet
3:06
to let's suppose I can say here
3:11
images just rename to images. And
3:13
basically here guys we can put a column
3:16
name which is called as picture URL. And
3:19
basically here we can resize this column
3:21
to create some spacing here. And you can
3:24
just go to your uh sites such as
3:26
unsplash.com or pixabay. These are two
3:30
completely free websites to download
3:32
free images. So no copyright is there.
3:36
So stock im footage you will see stock
3:39
images. So I can just search for my
3:42
favorite images. Let's suppose
3:44
programming.
3:46
So you can see these photographs are
3:47
there. So simply we can say right click
3:49
copy image address. So now we can simply
3:52
paste it inside our first row. Simply
3:55
paste. So this is you can see that guys
3:57
basically you can large this this is one
4:00
and similarly you can uh do it for any
4:03
image here let's suppose this one copy
4:05
image address once again paste it here
4:11
and similarly you can uh select this one
4:15
copy image address.
4:18
So you this process you need to do
4:20
manually. There are also scripts out
4:22
there which will automatically fetch
4:24
these images from the Unsplash. So I can
4:27
make this tutorial in a later video. But
4:29
for the sake of this you need to simply
4:32
copy paste the URLs here. These URLs can
4:35
be coming from a database as well. So if
4:36
you have a application the users are
4:38
uploading images you can also connect to
4:41
that service as well. So this will be
4:43
advanced tutorial. For this tutorial we
4:45
just need to manually do this process.
4:52
So after this guys,
4:55
if you see here,
5:01
[snorts] I think it is taking a lot of
5:03
space out there. Let me just
5:09
resize this column here.
5:19
Yes, you can see guys, this is the
5:20
column. Basically, we are resizing it
5:23
like this.
5:25
So, we can also increase the size of it
5:27
guys. Let's suppose you also need to
5:29
increase the size. You can select these
5:31
columns and right click and uh you can
5:33
simply say here uh you need to increase
5:36
the size. So what we can say is that we
5:39
can simply
5:42
uh there is option out there. Let me say
5:45
you just need to select these columns
5:47
here
5:49
and resize row. This is option. You can
5:52
change the height of this. Let's suppose
5:54
I change it to 60.
5:56
So now you can see
6:01
uh sorry let me
6:08
you need to select all these rows sorry
6:10
all these rows and then right click
6:16
and there is a option out there to
6:20
[snorts] so you can just do it like
6:22
this. So we have you can see we have
6:24
four images here. So now we need to
6:26
download the images right here in the
6:28
columns here these columns. So what we
6:31
can do is that basically we will simply
6:34
click this extensions option. Go to
6:36
appcript
6:38
and here we will be one by one
6:41
downloading the images. So for this we
6:44
need to write a function guys which will
6:46
be inserting the images from the URL.
6:50
So we will write this function and for
6:52
this guys we need to first of all get
6:54
the reference to the current sheet. We
6:56
can use this using spreadsheet app and
6:58
we will get the active sheet. Active
7:01
sheet method and basically this contains
7:04
the option which is get active sheet.
7:07
Get active cell
7:10
you can see that get active sheet. Sorry
7:12
not active cell get active sheet.
7:17
Get active spreadsheet. Sorry, this is a
7:20
method. Get active
7:23
spreadsheet.
7:24
This is a method. And here we need to
7:26
invoke get active
7:29
sheet. This is a method. So this will
7:31
get the current sheet guys we are on. We
7:34
will go to the last row of the image.
7:37
How many images are there? So we will
7:38
get to the last row by this function
7:40
which is get last row. And then we will
7:44
use a simple for loop guys. So we will
7:46
loop through iterate over all the URLs
7:48
which are there. So we will say last row
7:51
minus one. So just indexing start from
7:54
zero that's why I ++ and inside this
7:57
first of all we will get the URL guys of
7:59
the image by using sheet dot get range.
8:03
So basically here we are providing the
8:05
range guys of the columns. Here you'll
8:07
see it's uh a1
8:10
a2. We need to start from a2. So here we
8:14
need to put a formula here 2 + i. So for
8:17
each value of i guys the column will
8:20
remain constant which will be 1. These
8:22
rows number will change because 2 + 0
8:24
will be 2. This will be the first row. 2
8:27
+ 1 will be 3. 2 + 2 will be four. 2 + 3
8:30
will be five. So every time it will
8:32
iterate over all the rows. Here the
8:34
column will remain the same which is the
8:36
first column. That's why we are
8:37
providing the second argument to be one
8:39
all the time. And we need to get the
8:41
value of this column. So get value this
8:44
is a function we need to call here like
8:46
this. So this will get the actual image
8:48
URL. After this guys we need to insert
8:51
this or download this image from this
8:54
URL and insert it to a column called as
8:56
this column. This this this. So now we
9:00
need to loop through it and here we also
9:02
need to get spreadsheet app and here we
9:06
will say new cell image and here we will
9:09
be inserting the image inside the cell.
9:11
So that's why we are using this method
9:12
new cell image. Basically this method
9:15
what does it it creates a builder for a
9:17
cell image and basically we need to set
9:19
a URL. So this is contained the method
9:22
set source URL. And here we need to
9:24
provide the URL of the image which is
9:26
stored inside URL. That's it. After
9:28
doing this we need to simply move to the
9:31
next line sheet get range. And here we
9:34
will simply say 2 + i. Again this
9:37
formula two. This time the column name
9:41
will be two because we are moving to the
9:43
next column out there guys. This is a
9:45
column and the rows formula will remain
9:47
constant. 2 + 0 will be 2. 2 + 1 will be
9:51
3. 2 + 2 will be 4. 2 + 3 will be 5. So
9:55
here we are just changing the column to
9:57
be from 1 to 2. That's it. And we need
10:00
to set the value of this column.
10:03
Set value and the image. Whatever is the
10:05
image that we constructed. That's it. So
10:08
that's all guys. This is all the code
10:10
which is required here. So now if I save
10:12
this code here and basically if I now
10:15
run this code here. So what will happen
10:17
now you will see one by one these images
10:20
will be
10:22
first of all if you are running it for
10:23
the very first time you need to grant
10:25
the permission. So spreadsheet
10:27
permissions authorization is required.
10:29
So you need to select your account and
10:31
grant the necessary permission. So go to
10:34
advanc option. So this is totally same
10:36
because this is your own app. So it is
10:38
saying it will allow these permissions
10:40
of Google sheet. Simply click on allow.
10:43
And now as soon as you click allow the
10:46
images will be downloaded from these
10:48
URLs. It will be inserted. You will see
10:50
one by one.
10:54
You can see
10:59
[snorts]
11:04
execution completed.
11:07
Last row min - one
11:11
2 + i 1 get value.
11:33
So you can see that guys uh basically
11:38
Uh I think I have created some kind of a
11:41
problem here. Let me go backward here.
11:48
Undo. Control Z.
11:57
Yeah. Yeah. Control Z. So this was it.
12:00
You can see now we have four images out
12:02
there. So once again if I run this
12:04
script once again. Click on run.
12:06
[snorts] So basically execution started.
12:08
You will see one by one the images will
12:12
be downloaded.
12:16
Uh I think some images you can see only
12:18
this second image is working out there.
12:21
So I think there is uh the code is
12:23
correct here. You will see let me copy
12:25
paste this code once again. The code is
12:27
correct. Sometimes if you copy the copy
12:29
the URL of the image if it doesn't exist
12:32
then also it will take u
12:35
if you see once again if I run this
12:41
you will see first second third fourth
12:43
oh sorry there was just a typing mistake
12:45
out there guys. So you can see that now
12:47
it has successfully
12:52
let me increase the
12:58
uh you can see that the images have been
13:00
successfully downloaded and inserted in
13:02
the columns.
13:08
So now we need to download these images
13:10
inside your Google drive guys. So now we
13:12
will be writing the second function
13:14
which will actually directly upload
13:16
these images to Google Drive. So for
13:18
that you need to go to Google Drive here
13:20
and you need to create a folder some
13:22
kind of a folder. Simply click on uh new
13:26
folder and you need to simply say
13:29
uh sheet images.
13:32
Simply click on create and as soon as
13:35
your folder is created right click on
13:37
that folder click on share and basically
13:41
simply click on copy link anyone with
13:43
the link copy link. This is your link of
13:46
the folder. So if you now this is the ID
13:49
that you have given here. So simply you
13:52
need to paste the ID of this folder. So
13:54
this we will need here. So simply now do
13:56
this process. We will now write a
13:59
second function here
14:02
which is called as download image.
14:06
So you can directly just delete this
14:08
function. We don't no longer need this.
14:10
So we now we need to simply download the
14:13
images which are present inside the
14:14
sheet. So sheet and basically once again
14:17
spreadsheet app and we need to get the
14:20
active spreadsheet.
14:22
So once again the same code will be used
14:24
guys. get active sheet
14:30
the same logic will be used.
14:34
First of all we will again go to the
14:36
last row [snorts]
14:39
sheet dot get last row
14:43
and then we need to copy paste the ID of
14:45
this folder guys. So simply I will copy
14:48
paste the ID. Then we will simply run
14:50
this for loop once again. I is equal to0
14:53
last row minus one and I ++.
14:57
So inside this loop guys we need to get
14:59
the URL once again. So we will use once
15:01
again this get range function and inside
15:03
this the formula will be same guys 2 + i
15:07
1. So every time we will loop through
15:09
the urls here which are present. Column
15:11
name will be constant will be one
15:13
picture URL. This rows will be changing
15:16
2 + 0 2 2 + 1 3 as is. And after this we
15:21
need to get the value of this. So we
15:23
will get the URL value. After this we
15:26
need to convert this to a blob object
15:28
guys. So onceever you are downloading
15:29
the images into a folder you need to
15:32
convert them into a blob. For this we
15:35
will use the URL fetch app inside
15:37
[snorts] Google app script. It contains
15:39
this fetch method and basically it
15:41
converts the URL to a blob object.
15:45
And uh now in order to convert to blob
15:48
you have a function called as get blob.
15:50
So this contains returns the data into a
15:52
blob. And then we can simply just uh
15:56
transfer this into the folder create
15:58
file folder.create file.
16:02
And here we will transfer the blob.
16:03
That's it.
16:05
So now if you run this guys also you
16:08
need to grant permission for your Google
16:09
drive. So simply if you run this again
16:12
you need to create review permission and
16:16
[snorts] click on uh
16:19
basically now allow these
16:24
allow.
16:26
So now if you see one by one the images
16:29
will be downloaded inside your folder
16:30
which is sheet images. So if you see one
16:33
by one it will take the
16:37
URL of the images and it will download
16:39
this inside your folder.
16:46
So it is saying folder create file is
16:48
not a function
16:52
uh
16:55
folder.
16:57
Okay. Okay. Sorry
16:59
I [snorts] have made a problem guys. You
17:01
can see that it's
17:03
this needs to be drive drive app. So
17:06
drive app this contains a method get
17:08
folder by id. So that's why I was very
17:11
shocked why it wasn't asking for the
17:13
Google drive permission. So we haven't
17:15
used the drive app. So this is the
17:17
inside Google drive. We have a function
17:19
which is get folder by ID. We are
17:21
selecting the folder by its ID. Now if I
17:23
run this, we need to grant the
17:24
permission for Google Drive. If you see
17:27
if you run this now again you need to
17:28
grant the permission for Google Drive.
17:31
So this permissions are also only
17:33
granted for the very first time guys. So
17:35
in the subse subsequent runs you don't
17:37
need to allow you need not have to do do
17:41
this process again and again. So now if
17:43
you see [snorts]
17:45
it will download these images inside
17:47
your folder and you can see one by one
17:50
one image you can even open this image
17:53
as well. You can see this is the image.
17:58
All the four images have been
18:00
successfully downloaded guys. You can
18:02
see that you can download them inside
18:04
your local machine. So this is a very
18:06
simple process Google appcript how we
18:08
can download images from URL inside
18:10
Google sheet and also to Google drive.
18:12
All the source code is given in the
18:14
description of this video guys. So
18:16
please hit that like button, subscribe
18:17
the channel and I will be seeing you in
18:19
the next
