Project

General

Profile

Upload images using api cause images blank

Added by Chheun Phearaeun over 8 years ago

Hi there,

I am new to this redmine api. Recently, I've been trying to upload images from my php application through redmine api. Everything works ok but the images turn out blank. Please see the attachment.
Any idea?

function uploadFile($url, $token, $file) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url . 'uploads.json?key=' . $token);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curl, CURLOPT_HEADER, FALSE);
        curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);
        curl_setopt($curl, CURLOPT_POST, TRUE);
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($file));
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_VERBOSE, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            "Content-Type: application/octet-stream" 
        ));
        $execute = curl_exec($curl);
        if ($execute) {
            curl_close($curl);
            return $execute;
        }

        return curl_error($curl);
    }

    // calling api
    $api->uploadFile(REDMINE_URL, REDMINE_TOKEN, $attachment);