2

I'm using a REST API in Codeigniter and trying to set up an image upload method. I've managed to upload fine using a multipart form but get a file type error using the REST client below. I think the problem is "file_type" is showing as "application/octet-stream".

(Codeigniter Upload: http://codeigniter.com/user_guide/libraries/file_uploading.html)

REST Method

function do_upload_post()
{
    $config['upload_path'] = './savefiles/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';
    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload() )
    {
        print_r($this->upload->display_errors('', ''));
        print_r($this->upload->data());
    }
}

REST Client

function curl_upload(){
    $url = 'http://localhost/api/file/do_upload';
    $file = 'C:\inetpub\wwwroot\ds_site\designs\pics\file.jpg';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    $post = array(
        "userfile" => "@$file"
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $response = curl_exec($ch);
    echo $response;

    curl_close($ch);
}

Output

The filetype you are attempting to upload is not allowed.
Array
(
    [file_name] => aliens.jpg
    [file_type] => application/octet-stream
    [file_path] => C:/inetpub/wwwroot/ds_site/savefiles/
    [full_path] => C:/inetpub/wwwroot/ds_site/savefiles/aliens.jpg
    [raw_name] => aliens
    [orig_name] => 
    [client_name] => aliens.jpg
    [file_ext] => .jpg
    [file_size] => 103745
    [is_image] => 
    [image_width] => 
    [image_height] => 
    [image_type] => 
    [image_size_str] => 
)
2
  • Did you check this one : stackoverflow.com/questions/7495407/… ? Commented Jul 25, 2012 at 20:04
  • I hadn't see it actually. I've not tested the suggestions they discusa but the problems discussed are general upload file type issues and not specifically using cURL and I have managed to upload fine using a multipart/form. Commented Jul 25, 2012 at 20:43

1 Answer 1

1

It seems I needed to define the file type.

"userfile" => "@$file;type=image/jpeg"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.