1
00:00:00,150 --> 00:00:00,610
Wonderful.

2
00:00:01,050 --> 00:00:06,689
I think our local upload functionality works really well, but before we start tackling Cloud9, let's

3
00:00:06,689 --> 00:00:11,270
add some checks in our controller where I want to check if the image exists.

4
00:00:11,580 --> 00:00:17,340
So if the user is actually sending a file, if the file of users is an image file.

5
00:00:17,640 --> 00:00:24,570
And lastly, make sure that the size of the file is not bigger than specified and we're going to start

6
00:00:24,570 --> 00:00:26,200
by importing the errors.

7
00:00:26,520 --> 00:00:34,800
So the main error from the IRS, because if the check fails, then we're sending back the bad request

8
00:00:34,800 --> 00:00:35,430
response.

9
00:00:35,760 --> 00:00:36,960
So let's start over here.

10
00:00:36,980 --> 00:00:44,010
And unlike the previous project where I was the structuring of the errors, where I said, yep, I like

11
00:00:44,010 --> 00:00:50,490
to get the bad request, one or not found one in this case, I'm just going to get the entire object

12
00:00:50,850 --> 00:00:54,630
and then we'll use the dot to get the specific one.

13
00:00:55,170 --> 00:00:55,890
It's really up to you.

14
00:00:55,890 --> 00:00:59,210
If you want to use the structure method, you can definitely do so.

15
00:00:59,220 --> 00:01:05,910
In my case, for this project and probably for the remaining project, I'll just switch around and I'll

16
00:01:05,910 --> 00:01:12,600
get the entire object and then I'll specifically look for one of these options in the controller.

17
00:01:12,910 --> 00:01:18,290
And if this is blurry, you'll see that the second basically I want to come up with some kind of variable.

18
00:01:18,300 --> 00:01:23,450
In this case, I'm going to go with custom error and that is equal to require.

19
00:01:23,820 --> 00:01:26,470
And we're looking in the errors.

20
00:01:26,910 --> 00:01:29,340
So let me check over here errors.

21
00:01:29,700 --> 00:01:33,640
And then since I have the index, I don't have to specify anything.

22
00:01:33,990 --> 00:01:34,800
OK, awesome.

23
00:01:35,130 --> 00:01:41,580
And then let's start here by checking if the file exists now, how we can do that?

24
00:01:41,590 --> 00:01:49,230
Well, if we're going to log our files and if we go back here and just try to send something, we should

25
00:01:49,560 --> 00:01:51,420
see this object correct.

26
00:01:51,780 --> 00:01:59,820
But if the user is going to send a request without the file, then this one will be undefined.

27
00:01:59,820 --> 00:02:01,590
Basically, it's going to be empty.

28
00:02:01,950 --> 00:02:06,720
And the way we can check that, we can simply say if and will go with not.

29
00:02:06,990 --> 00:02:12,710
So if that Iraq files doesn't exist, then let's throw a customer.

30
00:02:12,990 --> 00:02:17,280
So let's just say here, throw new and we're looking for custom.

31
00:02:17,280 --> 00:02:22,080
And then like I said, since I'm getting the entire object, I'm just going to use the DOT syntax where

32
00:02:22,080 --> 00:02:24,480
I'm going to look for bad request error.

33
00:02:24,700 --> 00:02:27,330
I will say no file, upload it.

34
00:02:27,750 --> 00:02:33,300
And the way I'm going to do that in this video, I'll set up all the checks and then one by one will

35
00:02:33,300 --> 00:02:35,180
test them out in the postman.

36
00:02:35,340 --> 00:02:40,100
Otherwise, I think that she's going to be too much screen switching.

37
00:02:40,500 --> 00:02:44,330
So let's take a look at the terminal now and next.

38
00:02:44,340 --> 00:02:46,190
I want to check the format.

39
00:02:46,590 --> 00:02:53,370
And if I take a look at the image object in there, bunch of useful properties and the one that I'm

40
00:02:53,370 --> 00:02:55,500
looking for is the Monotype.

41
00:02:55,980 --> 00:03:00,810
And essentially I just want to check whether user is sending the image.

42
00:03:01,050 --> 00:03:07,580
So let me go below product image and I'll send in between the videos I just switched from to no big

43
00:03:07,650 --> 00:03:07,920
deal.

44
00:03:08,340 --> 00:03:14,910
I think I did it by mistake to begin with, so I just switched it back to const and then here.

45
00:03:15,720 --> 00:03:24,000
Let's go with Jeff and again will say, if not so, we're looking for product image, mime type, and

46
00:03:24,000 --> 00:03:30,240
then we'll use the starts with, which is just vanilla dress property that we can use on a string and

47
00:03:30,240 --> 00:03:31,080
also image.

48
00:03:31,380 --> 00:03:35,920
So if the mime type does not start with an image, what are we gonna do?

49
00:03:36,440 --> 00:03:36,740
Yep.

50
00:03:36,820 --> 00:03:46,310
You guessed that we want to send back the R and this case will say, please upload an image, let's

51
00:03:46,620 --> 00:03:46,800
it.

52
00:03:47,160 --> 00:03:53,970
And lastly, let's check for size, where essentially if we take a look at the image property monitors

53
00:03:53,970 --> 00:03:59,150
the size, the size is invite's and I'll start very small.

54
00:03:59,160 --> 00:04:00,700
I'll go with one km.

55
00:04:00,700 --> 00:04:05,880
But of course eventually I'll change that around to something more realistic.

56
00:04:05,880 --> 00:04:09,800
But just so we fail, I'm going to go with one Kalabi.

57
00:04:10,140 --> 00:04:14,310
And the way we do that, I mean, we don't have to come up with a variable.

58
00:04:14,520 --> 00:04:19,920
We can actually set it up in the entry as well if you want that max size.

59
00:04:20,130 --> 00:04:21,690
But in my case, I'm going to do it over here.

60
00:04:21,690 --> 00:04:23,370
I'll say max size is equal.

61
00:04:23,370 --> 00:04:28,590
And like I said, it's not very drastic with just one kilobyte and another check.

62
00:04:28,900 --> 00:04:39,210
I'll say if product image size is bigger than the max, then what are we do we send back the response.

63
00:04:39,540 --> 00:04:45,660
And in this case, let's just say please upload image.

64
00:04:46,660 --> 00:04:48,370
Emerge smaller.

65
00:04:49,410 --> 00:04:57,120
Smaller than and I think I'm going to go with one kilobyte, correct, so let's save it over here and

66
00:04:57,120 --> 00:05:01,160
then swing back to the postman removed from still locking up.

67
00:05:01,590 --> 00:05:02,940
I don't need that log anymore.

68
00:05:03,450 --> 00:05:09,020
And let's just try simply by sending an empty request where there is no file.

69
00:05:09,360 --> 00:05:13,260
So save it over here and we can see that we have no file uploaded.

70
00:05:13,470 --> 00:05:14,370
So that works.

71
00:05:14,700 --> 00:05:17,160
Then I want to send the doc file.

72
00:05:17,580 --> 00:05:19,230
So let me look at the documents.

73
00:05:19,230 --> 00:05:23,730
I'm going to go with the work course outlines and I'm looking for stock components.

74
00:05:23,730 --> 00:05:25,570
One centered over here.

75
00:05:25,630 --> 00:05:26,530
Yep, I have.

76
00:05:26,550 --> 00:05:28,020
Please upload image.

77
00:05:28,440 --> 00:05:36,270
And lastly, since I have that drastic file size, even if I go with correct image and I think in this

78
00:05:36,270 --> 00:05:43,410
case I'm going to go with image number six, I'll still get the response beforehand where I'll see the

79
00:05:43,410 --> 00:05:46,510
please upload image smaller than one gigabyte.

80
00:05:46,860 --> 00:05:49,770
So let me change it around to one megabyte.

81
00:05:50,280 --> 00:05:57,120
So let me do it over here where I have a thousand multiplied by one thousand twenty four.

82
00:05:57,540 --> 00:06:06,060
And now if I send the image, everything should be correct where I can see the path of uploads and whatever

83
00:06:06,300 --> 00:06:07,380
is the filename.

84
00:06:07,650 --> 00:06:14,430
And that's how we can set up a basic file upload on the server using the package by the name of Xpress

85
00:06:14,610 --> 00:06:15,810
file upload.

