I am coding an API using Phils RestServer (see link) in Codeigniter. I need a way to upload images via the API. How can I do that? Is it just as simple as making a POST request with the correct headers (what headers to use)?
https://github.com/philsturgeon/codeigniter-restserver
Thankful for all input!
Ok,
There is another solution here: FIle upload from a rest client to a rest server
But neither of these solutions worked for me.
However, this is what worked; actually worked.
First, I wasn't sure if my file was reaching the method, so I changed the response line to:
Note, this is a great way to test your REST methods.
You can also output:
and
etc.
I got the following JSON output:
So I knew my file was there.
I then changed the method to find and move the file. I used common file access script to get the file from its temp location and move it to a new location:
In looking at how amazon s3 does it here http://www.anyexample.com/programming/php/uploading_files_to_amazon_s3_with_rest_api.xml
It looks like on the client side you define the file type and then load it up in a variable with
file_get_contents($file_path)
and then send it with the appropriate headers defined in the example.Then on the server I assume it would be using
file_put_contents()
with the body of the request to save the file.try this code ,image is saved with time stamp and its extension ..
You can actually use CodeIgniter's native File Upload Class to facilitate uploads with Phil's Rest-Server like this:
Following is configuration of image path and their respective attributes setting in controller Form.php in form() function
{ $filenames = $this->fullimage_upload1($this->upload->data($imgfile)); return $filenames; }
This is the function defining upload the image copy to the different folders as small,thumbnails function fullimage_upload1($data) { $this->load->library('image_lib');