44
55use DateTime ;
66use Exception ;
7+ use Nurigo \Solapi \Exceptions \BaseException ;
78use Nurigo \Solapi \Exceptions \CurlException ;
89use Nurigo \Solapi \Exceptions \MessageNotReceivedException ;
910use Nurigo \Solapi \Libraries \Fetcher ;
@@ -55,9 +56,10 @@ public function send($messages, DateTime $scheduledDateTime = null): SendRespons
5556 /**
5657 * @param string $filePath 파일 경로
5758 * @param string $type 파일 유형(MMS, RCS, DOCUMENT, KAKAO)
58- * @return string|null
59+ * @throws Exception|CurlException
60+ * @return string
5961 */
60- public function uploadFile (string $ filePath , string $ type = "MMS " , $ name = null , $ link = null )
62+ public function uploadFile (string $ filePath , string $ type = "MMS " , $ name = null , $ link = null ): string
6163 {
6264 $ fileContent = file_get_contents ($ filePath );
6365 $ encodedFile = base64_encode ($ fileContent );
@@ -74,15 +76,11 @@ public function uploadFile(string $filePath, string $type = "MMS", $name = null,
7476 $ parameter ->setLink ($ link );
7577 }
7678
77- try {
78- $ result = $ this ->fetcherInstance ->request ("POST " , "/storage/v1/files " , $ parameter );
79- if (isset ($ result ->errorCode )) {
80- throw new Exception ();
81- }
82- $ response = new UploadFileResponse ($ result );
83- return $ response ->fileId ;
84- } catch (Exception $ exception ) {
85- return null ;
79+ $ result = $ this ->fetcherInstance ->request ("POST " , "/storage/v1/files " , $ parameter );
80+ if (isset ($ result ->errorCode )) {
81+ throw new BaseException ($ result ->errorMessage , $ result ->errorCode );
8682 }
83+ $ response = new UploadFileResponse ($ result );
84+ return $ response ->fileId ;
8785 }
8886}
0 commit comments