I just wrote web services for wordpress like login, register, pass update, etc...
Now I want to user can upload images from iOS device and send this via web services(query string). I am not sure how to do this.
For login I just create a query string like http://example.com/apps/login.php?user=something&pass=something and get all the data in php file and then update the wordpress DB and return success message in json_encode.
But for images, how I can create the query string and how I can get those images in php file.
Thanks in advance...
But for images, how I can create the query string
You DO NOT! It's not a place for that. If you need data uploaded, do it right way using HTTP POST request with data payload.
Related
I am developing a api using codeigniter for user signup and user update profile.
I have image field in form. To create user i have used post method which works fine.
But issue i am getting when i am updating user. I know that with put request we have to send urlencoded or json data. But what should i do to update image?
Should i make 2 request? One with normal url encoded data (PUT request) and one with post request (Update image).
In rest api development which is the significant way to deal with these type of request?
can anyone help me?
You can try Advance Rest API plug-ins or browser extension, or you can try postman software for testing api with multipart-formdata (images)
enter image description here
I'm creating this Cordova (Phonegap) app where I store users personal data (username and scores) every 60 seconds after which I want to display all users data to everybody (like scoreboard). For this I obviously need something to first gather all the data from users and then showing it to everybody.
I tried sending data with ajax to php for database storage. Then I tried sending data with ajax to php file to write the data in file, and finally realized that ajax won't work locally(?) (yes, I'm a novice). How do I create this kind of "global memory" that is accessible by all the users? How this is normally achieved in apps? I'm open for ideas.
Thanks.
You need a backend service, and call it from your application with webservices. You should send the data to your server (via webservice), store it in a database, and generate another call to send the scoreboard to every user.
Google about Rest APIS, choose the one you like.
For storing into the app, using localstorage is OK if the data is not too big. If it is, maybe you need to use SQLite, accesible from the cordova API.
I'm using phonegap build to create an app.
I've used a plugin for collection ids for sending push notifications, and also a plugin to register url schemes.
I have decided to use Google GCM service to send the notifications (I'm using PHP on the server).
When I create the notification message I can send the title and the message in the data json. But I also want to include a url for deep linking, something like:
myweirdapp://show.html?uid=467
How can I do that?
Thanks !
Use data json field to put your custom data in. See https://developers.google.com/cloud-messaging/server-ref#downstream
The WonderBird answer is almost correct.
You do need to add the data to the Json you are sending to GCM.
Then in your app you need to read this data if the notification was pressed and parse the result.
For instance, let's say you wanted to refer users to a different page. For this you have added to the Json the variable page=somepage.html
In the app you have to check if e.coldstart is true and then do something like location.href=e.payload.page
It's importent to notice that page is inside payload but coldstart is not.
I'm currently porting a webservice I've built to work with Google App Engine. One of the main functions in the webservice is to upload an image (a profile picture, for example). Currently what I do is:
Authenticate the user who wants to upload the image using his unique API KEY and other data.
Upload the file, give it a unique name and store the name of the file inside the user's row in the mysql database.
Now in order to port the file upload to App Engine I'm using Google Cloud Storage and following this tutorial:
https://cloud.google.com/appengine/docs/php/googlestorage/user_upload
I'm trying to get the file upload to work with my Android app the following way:
The user makes a request, the webservice authenticates him and sends in response the upload url created by CloudStorageTools::createUploadUrl.
The user uploads the image to this URL
Now heres the problem: After the upload is done, a POST is made to the given php file in createUploadUrl (I quote from google's docs) with the uploaded file. But how can this script know who uploaded the file it got? I can't pass any parameters indicating who uploaded the file to createUploadUrl so I can't insert the file name to a user in the Cloud SQL database, so now theres only a file not associated with anything in Cloud Storage.
Any hints? Am I missing something?
I'm posting this as a separate answer because a) it's different approach than the first answer, and b) I'd advocate for my other answer over this one because I think it's best to let GAE handle auth. However, I think you can do what you're trying to do this way:
Instead of routing a singular URL to your upload handler, use a regex match like this in your app.yaml to route any matching URLs to your handler:
handlers:
- url: upload_handler/(.*)
script: my-php-script-that-uploads-stuff.php
Then when invoking createUploadURL, simply pass in your API_KEY after the 'upload_handler/' as a query argument, e.g.
$upload_url = CloudStorageTools::createUploadUrl(sprintf('/upload_handler/?API_KEY=%s', $API_KEY), $options);
Then in my-php-script-that-uploads-stuff.php:
parse_str(parse_url($_SERVER['REQUEST_URI'])['query'])
This will parse the request URL to get the query string and then parse the query string, populating the value of API_KEY with the value passed in the URL in your local scope.
I just tested this pattern of extracting stuff from the request URL in a php script in with dev_appserver and it worked.
I think you can do this by using the google appengine users service in your php script.
From the link above, from the Overview page of the users service, here's how you get the current user:
use google\appengine\api\users\User;
use google\appengine\api\users\UserService;
$user = UserService::getCurrentUser();
I'm fairly new with CakePHP and images so bear with me. You can assume I'm using the latest version.
I'm trying to build an Android application which can display images retrieved from the server.
Suppose I have an image in the assets folder called football.jpg. How would I store this in the database and then how would I output this to the Android application? Do I send only the link or do I send the whole image over? If it is just the link, does this mean I would have to reconnect to the server with the link and then get the image? Sorry if this doesn't make sense. Still trying to get my head around it.
Just a word of caution, it's probably better to store the file on the server's file system and store the path to the file in the database. The reason behind this is that BLOBs are stored in a different area on the file system to all your other typical data and in terms of retrieval, its not a great deal faster.
Here's a link to what I mean: Store pictures as files or in the database for a web app?
With regards to returning it to your Android app, you can send files in the response object (http://book.cakephp.org/2.0/en/controllers/request-response.html#cake-response-file):
public function sendFile($id) {
$file = $this->Attachment->getFile($id);
$this->response->file($file['path']);
//Return reponse object to prevent controller from trying to render a view
return $this->response;
}
This should give you finer control over what files are returned to your client.