Codeigniter 从rest客户端到rest服务器的文件上载

Codeigniter 从rest客户端到rest服务器的文件上载,codeigniter,restful-authentication,Codeigniter,Restful Authentication,我使用PhilSturgeon创建的codeigniter rest server库创建了一个rest服务器: 现在,我正在使用Codeignitor rest客户端: 从rest服务器获取/发布数据,并成功获取/发布正常数据 从rest客户端将图像文件发布到rest服务器的最佳方式是什么 另外,假设rest服务器使用摘要身份验证,如何从C#.NET访问API并执行所有get/post操作?[任何可用的库?]正如Amit所建议的,您可以发送文件的内容file\u get\u contents

我使用PhilSturgeon创建的codeigniter rest server库创建了一个rest服务器:

现在,我正在使用Codeignitor rest客户端:

从rest服务器
获取
/
发布
数据,并成功获取/发布正常数据

从rest客户端将图像文件发布到rest服务器的最佳方式是什么


另外,假设rest服务器使用摘要身份验证,如何从C#.NET访问API并执行所有get/post操作?[任何可用的库?]

正如Amit所建议的,您可以发送文件的内容
file\u get\u contents('foo.jpg')
,或者您可以执行更符合规范的操作并执行以下操作:

帖子/图片

内容类型:图像/jpeg

然后,对于主体,您只需设置图像的内容(或您正在触发的任何类型的文件)

然后,您可以通过以下方法在PHP中获取:

file_get_contents('php://input');

这将包含您图像的内容,因此您可以将其保存在任何位置。

我实际上能够使用CodeIgniters本机文件上载类来解决相同的问题:

这些解决方案对我不起作用。但是,我在这里发布了我的解决方案:


简单的Rest Post服务,用于从任何Rest客户端上载和存储文件

public function product_post()
{
    $uploaddir = './uploads/products/';
    $file_name = underscore($_FILES['file']['name']);
    $uploadfile = $uploaddir.$file_name;

    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
        $dataDB['status'] = 'success';       
        $dataDB['filename'] = $file_name;
     } else {
        $dataDB['status'] =  'failure';       
     }
     $this->response($dataDB, 200);
}

经过一天多的搜索,终于找到了适合我的方法

public function upload_post()
    {
      $config['upload_path'] = './uploads/';
      $config['allowed_types'] = '*';

      $this->load->library('upload');
      $this->upload->initialize($config);

      if ( ! $this->upload->do_upload('file'))
      {
        $error = array('error' => $this->upload->display_errors());
         print_r($error);
      //  $this->load->view('upload_form', $error);
      }
      else
      {
        $data = array('upload_data' => $this->upload->data());
        print_r($data);
      //  $this->load->view('upload_success', $data);
      }
    }

好吧PhilSturgeon给了我一个方法。。。将文件\u获取\u内容(ImageFile)作为POST变量从客户端发送到服务器,并在服务器端通过文件\u放置\u内容($\u POST['ImageFile'])创建图像文件。。。但现在的问题是,当我在服务器上接收到它时,一些字符(如ÿØÿ)被剥离,图像并没有完美地创建。为了克服这个剥离问题,在发送之前,我在客户端将图像数据编码为base64格式,然后在服务器端对其进行解码,效果非常好。还有其他解决办法吗?这是最好的方法吗?你应该将此过程作为答案发布。这确实是最好的解决方案。我尝试了这段代码,但得到了错误数组([错误]=>您没有选择要上载的文件。)请让我知道如何设置post参数和标题