@@ -685,6 +685,11 @@ public function upload($filepath, $options = [])
685685 $ location = $ options ['location ' ];
686686 }
687687
688+ $ path = '' ;
689+ if (array_key_exists ('path ' , $ options )) {
690+ $ path = $ options ['path ' ];
691+ }
692+
688693 $ filename = basename ($ filepath );
689694 if (array_key_exists ('filename ' , $ options )) {
690695 $ filename = $ options ['filename ' ];
@@ -701,6 +706,7 @@ public function upload($filepath, $options = [])
701706 'filesize ' => filesize ($ filepath ),
702707 'mimetype ' => $ mimetype ,
703708 'location ' => $ location ,
709+ 'path ' => $ path ,
704710 ];
705711
706712 // register job
@@ -782,6 +788,90 @@ public function uploadUrl($resource, $options = [])
782788 return $ filelink ;
783789 }
784790
791+ /**
792+ * Get Doc Detection is used for get coords or process image filelink
793+ *
794+ * @param string $resource URL or Handle or Storage path
795+ * pass into this function
796+ * @param array $options extra optional params. e.g.
797+ * coords (bool, true|false),
798+ * preprocess (bool, true|false)
799+ *
800+ * @throws FilestackException if API call fails
801+ *
802+ * @return Filestack\Filelink
803+ */
804+ public function getDocDetection ($ resource , $ options = [])
805+ {
806+ // generate url
807+ $ url = $ this ->getDocDetectionUrl ($ resource , $ options );
808+
809+ // send get request
810+ $ response = $ this ->sendRequest ('POST ' , $ url );
811+ $ status_code = $ response ->getStatusCode ();
812+
813+ if ($ status_code !== 200 ) {
814+ throw new FilestackException ($ response ->getBody (), $ status_code );
815+ }
816+
817+ $ json_response = json_decode ($ response ->getBody (), true );
818+
819+ if (array_key_exists ('coords ' , $ json_response )) {
820+ return [
821+ 'data ' => $ json_response
822+ ];
823+ } else {
824+ return [
825+ 'url ' => $ json_response ['url ' ],
826+ 'mimetype ' => $ json_response ['type ' ],
827+ 'size ' => $ json_response ['size ' ]
828+ ];
829+ }
830+ }
831+
832+ /**
833+ * Get Doc Detection Url is used for generate full request url
834+ *
835+ * @param string $resource URL or Handle or Storage
836+ * pass into this function
837+ * @param array $options extra optional params. e.g.
838+ * coords (bool, true|false),
839+ * preprocess (bool, true|false)
840+ *
841+ * @return string it will return generated url
842+ */
843+ public function getDocDetectionUrl ($ sources , $ options = [])
844+ {
845+ if (!array_key_exists ('coords ' , $ options )) {
846+ $ options ['coords ' ] = 'false ' ;
847+ } else {
848+ $ options ['coords ' ] = filter_var ($ options ['coords ' ], FILTER_VALIDATE_BOOLEAN ) ? 'true ' : 'false ' ;
849+ }
850+
851+ if (!array_key_exists ('preprocess ' , $ options )) {
852+ $ options ['preprocess ' ] = 'true ' ;
853+ } else {
854+ $ options ['preprocess ' ] = filter_var ($ options ['preprocess ' ], FILTER_VALIDATE_BOOLEAN ) ? 'true ' : 'false ' ;
855+ }
856+
857+ $ url = sprintf ('%s/API_KEY/security=p:%s,s:%s/doc_detection=coords:%s,preprocess:%s/%s ' ,
858+ $ this ->getCustomUrl (FilestackConfig::CDN_URL ),
859+ $ this ->security ->policy ,
860+ $ this ->security ->signature ,
861+ $ options ['coords ' ],
862+ $ options ['preprocess ' ],
863+ $ sources
864+ );
865+
866+ if ($ this ->hasHttpOrHttps ($ sources )) {
867+ $ url = str_replace ("/API_KEY " , "/ {$ this ->api_key }" , $ url );
868+ } else {
869+ $ url = str_replace ("/API_KEY " , "" , $ url );
870+ }
871+
872+ return $ url ;
873+ }
874+
785875 /**
786876 * Bundle an array of files into a zip file. This task takes the file or files
787877 * that are passed in the array and compresses them into a zip file. Sources can
0 commit comments