文件从 REST 客户端上传到 REST 服务器

发布于 2024-10-09 16:28:48 字数 569 浏览 0 评论 0原文

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

github.com/philsturgeon/codeigniter-restserver< /a>

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

github.com/philsturgeon/codeigniter-restclient

从/向其余服务器获取/发布数据,并且能够成功获取/发布正常数据。

从其余客户端将图像文件发布到其余服务器的最佳方法是什么?

另外,假设其余服务器使用摘要身份验证,如何才能访问 API 并从 C# .NET 执行所有 get/post 操作? [有可用的图书馆吗?]

I created a rest server using the codeigniter rest server library created by PhilSturgeon :

github.com/philsturgeon/codeigniter-restserver

Now, I am using Codeignitor rest client :

github.com/philsturgeon/codeigniter-restclient

to get/post data from/to the rest server and am successfully able to get/post normal data.

What is the best way to post image files to the rest server from the rest client ?

Also, how can someone can access the API and perform all get/post operation from C# .NET assuming the rest server uses digest authentication ? [any library available ?]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

幸福%小乖 2024-10-16 16:28:48

简单的休息邮政服务上传和下载存储来自任何 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);
}

Simple Rest Post service to upload & store a file from any Rest client

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);
}
苍风燃霜 2024-10-16 16:28:48

经过 1 天多的搜索,终于这对我有用

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);
      }
    }

After searched for more than 1 days, finally this is what worked for me

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);
      }
    }
残花月 2024-10-16 16:28:48

正如 Amit 所建议的,您可以发送文件 file_get_contents('foo.jpg') 的内容,或者您​​可以做一些更符合规范的事情,例如:

发布/图片

内容类型:图像/jpeg

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

然后,您可以在 PHP 中使用以下命令来获取它:

file_get_contents('php://input');

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

As Amit has suggested, you can send the contents of a file file_get_contents('foo.jpg') or you could do something more true to the spec and do something like:

POST /images

Content-Type: image/jpeg

Then for the body you just set the contents of the image (or whatever type of file you're firing off).

You can then pick that up in your PHP with:

file_get_contents('php://input');

That will have the contents of your image, so you can save it wherever.

_蜘蛛 2024-10-16 16:28:48

我实际上能够使用 CodeIgniters 本机文件上传类来解决同样的问题: https://stackoverflow.com/a/11163068/1188523

I was actually able to use CodeIgniters native File Upload class to solve this same issue: https://stackoverflow.com/a/11163068/1188523

浅浅淡淡 2024-10-16 16:28:48

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

Codeigniter 和 RestServer。如何上传图片?

These solutions did not work for me. However, I posted my solution here:

Codeigniter and RestServer. How to upload images?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文