Hi I'm trying to figure out how to upload to imgur using java, does anyone have any experience with this kind of thing?
First of all, you're likely to be best off using the imgur api.
The documentation for uploading contains examples for Python and PHP that use cURL. It should be possible to adapt these to the Java bindings for cURL, or other HTTP libraries such as HttpClient.
Get a developer key.
Look at their Image Upload API.
Use Apache Commons HttpClient to create a POST request and send:
'image' - A binary image file, base64 encoded string, or URL.
'key' - Your registered developer API key. Click here to register for a key.
You could try cURL. http://curl.haxx.se/libcurl/java/
I've used HtmlUnit with great success for this sort of tasks. Read the Submitting a form in the Getting started section, and you'll be done in no time.
Related
I'm developing a server in Java which will provide URLs for images that clients uploaded. Basically the Android/iOS will send some kind of data (I still don't know which data would be sent for image and videos) then I'll upload those images/videos to Google Storage and provide URLs which the users (Android/iOS) will be able to stream.
I've just started with Google Storage and I can't find any example of how to upload an image using Java. All examples I found or are deprecated or it's in PHP or it's not clean.
I think I will need to use the JSON client Library but I can't find a good example for this library either.
Please any help will be VERY appreciate.
Based on your answer to my comment above, you could use the method I described in the following Stack Overflow response in order to save the file from your servlet to the Datastore and return the URL:
How to return a file with Google Cloud Endpoints?.
The two differences between your requirements and the method described in this response are:
The way the file is created: in your case through a file input stream, as you mentionned
The way you return the URL: since you will probably not use Google
Endpoints (because of file input stream) you don't need to return the URL in a string wrapper.
Sorry if this is a little general. Hopfully I can get pointed in the correct direction.
I have an android app that includes instant messaging. I want to add the functionality to send photos in messages as well. My backend is built on GAE and cloud endpoints and is written in Java.
So far, I've looked into google cloud storage, the blobstore, java servlet pages, etc. But a clear solution (or example using endpoints) has been impossible to find.
So, as the question states, how can I send and serve images from the blobstore using android and GAE endpoint backend?
Edit: This question is only regarding the back end. In android, I can do the http post easily enough. I'm just lost when it comes to doing this in endpoints
I suggest the following approach to implement what you require:
Pass the image data as base64 encoded text from your client.
On the server side, you can extract out the image content and then use one of many options that are available, which include Blobstore, Google Cloud Storage, etc. I suggest that you go with Google Cloud Storage because that is the recommended approach. If you prefer the Datastore, keep in mind that the data is limited to 1 MB in size, so you might hit that limit depending on the size of images that you are dealing with.
A SO question and answer here contains lot of relevant code that you could utilize: Sending images as a base64 string to a google cloud endpoint from cms
Why not using a simple HTTP POST to handler for image upload?
When I use the blobstore I typically have a pair of handlers one for uploading and one for serving images.
So, in your case I'll rather do a post to a URL sending the image file and some parameter than can link it to the proper place in the datastore (i.e. user ID).
Then, using endpoints I'll have the same linking key and display the image using the serving handler with the given parameter.
If you are already using endpoints you can follow #Romin 's suggestion and send the images as Base64 or upload your images in 2 steps using the blobstore/GCS service, first get the Upload URL (via endpoints) and then post your image to that URL.
i had used eclipse to develop an android apps that can allow user to register.
after they register successfully and go into the main page, they are able to see their own profile which consists of the details they keyed in during register. (The details will saved into phpmyadmin)
any method can retrieve those details from the database and display it on the profile page? (i am using php and java)
thanks for answering..
You can always use "Zend AmF" or "AMF PHP" for comunicating with the app, binary.
http://www.silexlabs.org/amfphp/
http://framework.zend.com/manual/1.12/en/zend.amf.html
or amf mixed with codeigniter
https://github.com/EllisLab/CodeIgniter
Then use:
- http://code.google.com/p/klio-mobile-dataservice/
to connect with your server
You need to have a server, like a Tomcat, or anyother server, to which you will post the data
The Servlet or the PHP script, will read the values, store them in database.
The Android application will get the data from another Servlet or a PHP page, using a HTTP Get request, and show it on the screen.
You can alternatively, store the keys locally in the device, using SharedPreferences, and get them in the next screen.
You have to write a php script wich parses data from your database into for example JSON-Format. If you had parsed the json you can use the JSON parser in android to show he content in your activitys.
Here is a very nice tutorial for json parsing in android:
http://www.androidhive.info/2012/01/android-json-parsing-tutorial/
Basically you have to create Web Service in PHP or Java and from there you need to get your data.
You have to create Restful API which returns data in the form of XML or JSON and you need to parse those data at android end. By this way you can get your data from PHP.
Here is the best resource which i found when i was searching for this kind of scenario. The author has explained very well in this and you will get very good idea about the scenario. Also provide sample code for reference.
Refer this link.
Hope this helps!
I have a java program at the client side from which I need to send an image to upload to the server running the php script.
Can anyone please suggest ways of doing this?
You'll need to send an HTTP POST request with the image data included as the body.
As for a java solution, here's a similar post:
How to upload binary data using POST
I want to access a MySQL database from Java, but remote connection is disabled by the host.
So I will send the data to PHP and then PHP will locally access the database.
The data is pretty big (about 2~4kb)
I've never done this before.
What should I do?
Probably the best way would be to write a web service in PHP that you call from Java.
Another somewhat easier way would be to use the HttpURLConnection class to simply do a POST of the data to the PHP page.
If the PHP page is publicly accessible, you'd want to make sure you have some kind of authentication mechanism in place and use HTTPS as well.
Http web-services
Sounds like your only option is to create a Web Service. You can use Apache's HttpClient in Java to create requests and have your PHP return a response that you can easily parse. Depending on what you are trying to do, an XML response might be overkill. I've used JSON in the past if I know exactly what I am getting back.
I assume the Java program will be the client. I think the simplest would be to just create a simple PHP page, POST any possible parameters to that page from Java, and return the data as a JSON structure.
There are a number of JSON tools for Java and PHP listed on JSON page: http://json.org/
You might want to have a look to Thrift:
http://incubator.apache.org/thrift/
Are you saying that you are going to run java from php, so that php has the handle to the mysql database and you will pass the data to java?
check out java php bridge