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.
Related
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 need a help with upload a file to google storage(blobstore or google cloud storage), and i already did that send a message to server and then the server will response the message back.
There are the code i alredy did a little bit below, could anyone help me how to upload a file to clound storage by using java application.
I dont use jsp or html as a upload interface, i design a simple javaGUI to upload a file when click a upload button.
I can not find any reference online, most of cases used jsp, html or php as a interface to upload a file.
i had some problem with code posted, so i put my code in the dropbox.
Server side:
enter link description here
Client side:
enter link description here
First of all you will have to complete the fully functional example that actually works for uploading files on Blobstore or Google Cloud Storage. No matter what are you going to use for uploading stuff, this is a must thing to do to verify that the backend part works and the part that is done in JSP will be your testing environment for making sure that the backend works before implementing anything else.
Once this is done then all you have to do from your JavaGUI app is to make sure that you know how to upload files using the the multipart file upload POST request.
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!
My application generates binary data (compressed xml) and saves it to the Google App Engine Blobstore. I want to return a public URL that clients can use to access this binary file from anywhere, without needing to go through AppEngine and my Java servlets. I know it's possible to get this kind of URL for images using ImagesService#getServingUrl, but what about for other types of files?
I create my file like this:
FileService#createNewBlobFile("application/octet-stream", "myfile.bin");
When I call AppEngineFile#getFullPath() I get something like:
/blobstore/writable:a2c0noo4_LNQ0mS6wFdCMA
I can see the file created in my dev filesystem with a different random name. What's its URL?
You can use Google Cloud Storage for your file.
You can then provide a public cloud storage URL for you file that will allow you clients to download it without going through AppEngine. There are a whole lot of different ACL scenarios you can use to tighten down the access as well, it's in the docs.
Using Google Cloud Storage with the Files API.
Cloud Storage Docs.
According to the docs, there's no public URL for objects in the blobstore. You can only access it through the Blobstore API from your app. So if you want your blobstore objects to each have a URL, you'd have to create your own handler for that, which of course will have to pass through AppEngine and your Java servlets.
I think the ImagesService#getServingUrl doesn't generate a Public URL for the images in blobstore. That URL doesn't really point directly to your blobstore data. It points to an image service that is able to access your blobstore, and serves your image for you through its own high performance infrastructure.
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.