Skip to content

Commit 3e84921

Browse files
ANKUR DWIVEDIANKUR DWIVEDI
authored andcommitted
added checks parameter
1 parent 4f2194f commit 3e84921

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ echo $imageURL;
122122
$uploadFile = $imageKit->uploadFile([
123123
'file' => 'file-url', # required, "binary","base64" or "file url"
124124
'fileName' => 'new-file' # required
125+
'checks' => '"file.size" < "1mb"' // optional `checks` parameters can be used to run server-side checks before files are uploaded to the Media Library.
125126
]);
126127
```
127128

@@ -562,6 +563,7 @@ The SDK provides a simple interface using the `$imageKit->uploadFile()` method t
562563
$uploadFile = $imageKit->uploadFile([
563564
'file' => 'your_file', // required, "binary","base64" or "file url"
564565
'fileName' => 'your_file_name.jpg', // required
566+
'checks' => '"file.size" < "1mb"', // optional `checks` parameters can be used to run server-side checks before files are uploaded to the Media Library.
565567
]);
566568
```
567569
#### Response
@@ -657,6 +659,7 @@ $uploadFile = $imageKit->uploadFile([
657659
]
658660
]
659661
],
662+
'checks' => '"file.size" < "1mb"', // optional `checks` parameters can be used to run server-side checks before files are uploaded to the Media Library.
660663
// "customMetadata" => [
661664
// "SKU" => "VS882HJ2JD",
662665
// "price" => 599.99,

src/ImageKit/Constants/ErrorMessages.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class ErrorMessages
4949
public static $UPLOAD_FILE_PARAMETER_OPTIONS_INVALID_TRANSFORMATION = [ "message" => "Invalid transformation parameter. Please include at least pre, post, or both.", "help" => "For support kindly contact us at [email protected] ."];
5050
public static $UPLOAD_FILE_PARAMETER_OPTIONS_INVALID_PRE_TRANSFORMATION = [ "message" => "Invalid pre transformation parameter.", "help" => "For support kindly contact us at [email protected] ."];
5151
public static $UPLOAD_FILE_PARAMETER_OPTIONS_INVALID_POST_TRANSFORMATION = [ "message" => "Invalid post transformation parameter.", "help" => "For support kindly contact us at [email protected] ."];
52+
public static $UPLOAD_FILE_PARAMETER_OPTIONS_INVALID_CHECKS = [ "message" => "The value provided for the checks parameter is invalid.", "help" => "For support kindly contact us at [email protected] ."];
5253
public static $MISSING_UPLOAD_DATA = ['message' => 'Missing data for upload', 'help' => 'For support kindly contact us at [email protected] .'];
5354
public static $MISSING_UPLOAD_FILE_PARAMETER = ['message' => 'Missing file parameter for upload', 'help' => 'For support kindly contact us at [email protected] .'];
5455
public static $MISSING_UPLOAD_FILENAME_PARAMETER = ['message' => 'Missing fileName parameter for upload', 'help' => 'For support kindly contact us at [email protected] .'];

src/ImageKit/ImageKit.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ public function uploadFile($options=null)
216216
return Response::respond(true, ((object)ErrorMessages::$UPLOAD_FILE_PARAMETER_OPTIONS_INVALID_POST_TRANSFORMATION));
217217
}
218218
}
219+
if(isset($options['checks']) && !is_string($options['checks'])){
220+
return Response::respond(true, ((object)ErrorMessages::$UPLOAD_FILE_PARAMETER_OPTIONS_INVALID_CHECKS));
221+
}
219222
}
220223

221224

tests/ImageKit/Upload/UploadTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public function testFileUploadIfSuccessful()
172172
]
173173
]
174174
],
175+
'checks' => "'request.folder' : '/sample-folder'"
175176
];
176177

177178
$mockBodyResponse = Utils::streamFor(json_encode($this->uploadSuccessResponseObj));
@@ -215,6 +216,7 @@ public function testFileUploadIfSuccessful()
215216
$this->checkFormData($stream,$boundary,"overwriteCustomMetadata","true");
216217
$this->checkFormData($stream,$boundary,"customMetadata",json_encode($fileOptions['customMetadata']));
217218
$this->checkFormData($stream,$boundary,"transformation",json_encode($fileOptions['transformation']));
219+
$this->checkFormData($stream,$boundary,"checks",$fileOptions['checks']);
218220

219221
// Assert Method
220222
$requestMethod = $container[0]['request']->getMethod();
@@ -785,6 +787,32 @@ public function testFileUploadWithInvalidTransformationTypePostTransformation()
785787
UploadTest::assertEquals(json_encode($error),json_encode($response->error));
786788
}
787789

790+
791+
/**
792+
*
793+
*/
794+
public function testFileUploadWithInvalidChecks()
795+
{
796+
$fileOptions = [
797+
'file' => 'http://lorempixel.com/640/480/',
798+
'fileName' => 'test_file_name',
799+
"useUniqueFileName" => true, // true|false
800+
"responseFields" => implode(",", ["tags", "customMetadata"]), // Comma Separated, check docs for more responseFields
801+
'checks' => true
802+
];
803+
804+
$error = [
805+
"message" => "The value provided for the checks parameter is invalid.",
806+
"help" => "For support kindly contact us at [email protected] ."
807+
];
808+
809+
$this->stubHttpClient(new Response(403, ['X-Foo' => 'Bar'], json_encode($error)));
810+
811+
$response = $this->client->uploadFile($fileOptions);
812+
813+
// Request Body Check
814+
UploadTest::assertEquals(json_encode($error),json_encode($response->error));
815+
}
788816

789817
protected function setUp()
790818
{

0 commit comments

Comments
 (0)