FIle upload from a rest client to a rest server

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 ?]


简单休息发布服务来从任何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);
}

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.


我实际上可以使用CodeIgniters原生的File Upload类来解决这个问题:https://stackoverflow.com/a/11163068/1188523

链接地址: http://www.djcxy.com/p/49540.html

上一篇: ASP.NET Web应用程序(MVC)部署自动化和Subversion

下一篇: 将文件从其余客户端上传到其余服务器