최근 검색


최근 검색 없음

Amir S.'s Avatar

Amir S.

가입한 날짜: 2024년 3월 31일

·

마지막 활동: 2024년 5월 27일

팔로잉

0

팔로워

0

총 활동 수

3

투표 수

0

가입 플랜

1

활동 개요

님의 최근 활동 Amir S.

Amir S.님이 에 댓글을 입력함

커뮤니티 댓글 Developer - Zendesk APIs

foreach ($files as $key => $file)

      {

        $attachmentFile = $this->uploadAndGetPath($file);

        $attachmentMime = 'application/binary';

        $tmp = explode('/', $attachmentFile);

          $file_name = end($tmp);

        $tmp = explode('.', $attachmentFile);

          $file_extension = end($tmp);

        if ($file_extension=='pdf') { $attachmentMime = 'application/binary'; } // application/pdf

        if ($file_extension=='zip') { $attachmentMime = 'application/zip'; }

        if ($file_extension=='jpg') { $attachmentMime = 'image/jpeg'; }

        if ($file_extension=='png') { $attachmentMime = 'image/png'; }


 

        $headers = array();

        $headers[] = 'Content-Type: '.$attachmentMime;

        $headers[] = 'Authorization: Basic '.base64_encode(config('zendesk.username').':'.config('zendesk.token'));


 

        $attachmentFileData = file_get_contents(Storage::url($attachmentFile));


 

        $ch = curl_init();

              curl_setopt($ch, CURLOPT_URL, 'https://'.config('zendesk.sub_domain').'.zendesk.com/api/v2/uploads.json?filename='.$file_name);

              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

              curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

              curl_setopt($ch, CURLOPT_POST, 1);

              curl_setopt($ch, CURLOPT_POSTFIELDS, $attachmentFileData);

        $result = curl_exec($ch);

        $result = json_decode($result,true);

        curl_close($ch);


 

        $uploadTokens[] = $result['upload']['token'];

        //unlink(getcwd().'/'.$attachmentFile);

      }

댓글 보기 · 2024년 5월 27일에 게시됨 · Amir S.

0

팔로워

0

투표 수

0

댓글


Amir S.님이 에 댓글을 입력함

커뮤니티 댓글 Developer - Zendesk APIs

Issue still occurs to me with image files. 
Code below for PDF uploads works! (using Content-Type: application/binary);

PHP/laravel, curl and correct content-type used. 
Any thougths? 

    $headers = array();

    $headers[] = 'Content-Type: image/jpeg';

    $attachmentUrl = 'https://storage.googleapis.com/orderaprint/orders/149872/367636_gooten_tote_bag_1711868333.jpg';

    $attachmentFileData = file_get_contents($attachmentUrl);


 

    $ch = curl_init();

          curl_setopt($ch, CURLOPT_URL, 'https://'.config('zendesk.sub_domain').'.zendesk.com/api/v2/uploads?filename=test.jpg');

          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

          curl_setopt($ch, CURLOPT_POST, 1);

          curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

          curl_setopt($ch, CURLOPT_USERPWD, config('zendesk.username').':'.config('zendesk.token'));

          $post = array('file' => $attachmentFileData);

          curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

    $result = curl_exec($ch);

    print_r($result);

    curl_close($ch);

    die();

댓글 보기 · 2024년 3월 31일에 게시됨 · Amir S.

0

팔로워

0

투표 수

0

댓글