Request request = Request.newUploadPhotoRequest(Session.getActiveSession(),imageToBeUploaded,new Request.Callback() {
#Override
public void onCompleted(Response response) {
showPublishResult(getString(R.string.photo_post),response.getGraphObject(), response.getError());
}
});
ATM I am uploading to facebook by passing a bitmap.
But i have to upload photos from my website. So i download the image in AsyncTask and pass it here
Is there any method to upload via url using non depreciated methods ?
There is no documented way of doing this that I know of, you could use https://developers.facebook.com/docs/reference/api/batch/ (look at the Uploading Binary Data section) , and put in your url requests, but I think the best way is to download the file locally and post it as data , this way you can control the url content
Related
I managed to upload the blob from Javascript to Java Endpointfunction
Javascript
var request = gapi.client.helloworldendpoints.uploadImage({
'imageData': __upload.imageData,
'fileName': __upload.fileName,
'mimeType': __upload.mimeType,
'size': __upload.size
});
Java Endpoint
public ImageUploadRequest uploadImage(
Request imageData,
#Named("fileName") String fileName,
#Named("mimeType") String mimeType,
#Named("size") float size
) { ... }
Request is just this
public class Request {
public Blob image;
}
Now i want to send a MultipartRequest from my Java Endpoint at GAE to my UploadServlet to create a blobkey and save the data into blobstorage, since Blobstorage only accepts data send to servlet. How can I create a MultipartRequest?
There are numerous ways to construct an HTTP request in Java. This question, while dealing with some very specific systems, is too broad for Stack Overflow, since the real question is "how can I build and execute a multi-part/form-data request in Java?" You should look into the UrlFetch service on App Engine, since this is how all HTTP requests are sent. You can find examples of HTTP requests in Java all over the internet.
I have an android app that wants to include image sending in the instant messaging client. I'm terribly confused on the way to do this using the blobstore or google cloud storage. Can someone please outline the steps to achieve this from the backend perspective? My goal is to end up using getServingUrl and have an external url for the app to hit and get the image. I'm using java and google cloud endpoints.
So far, I have:
1. createUploadUrl
2.user blogstore service .getUploads() to get BlobKeys
3.find my specific blob key (by ID, blobs.get(ID) i think)
4. magic
5. figure out how to use .getServingUrl(options) on a specific blob
6. backend works.
Please include code or psuedocode in your response, as I've been working on this for days and am beyond exhausted. I could really use someone to ELI5.
I think the confusing thing is trying to use it with cloud endpoints, which is not what you are supposed to do. Use a pure Servlets (or an abstraction over Servlet which gets you access to HttpServletRequest).
Get the BlobKey using BlobstoreService.getUpload(HttpServletRequest):
public void doGet(HttpServletRequest request, HttpServletResponse response) {
BlobKey blobKey = blobstoreService.getUploads(request).get("file").get(0); // assume the form parameter was "file" and only one file was uploaded
}
and use ImagesService.getServingUrl (set the BlobKey in the Options builder) to get the URL.
String url = imagesService.getServingUrl(ServingUrlOptions.Builder.withBlobKey(blobKey));
You may want to serialize the BlobKey (with getKeyString) to the datastore for future access.
I'm trying to use the code below to upload image to blobstore using curl and I get the following error "Must be called from a blob upload callback request".
However if I use a form with an action it does upload:
blobstoreService.createUploadUrl("/upload")
===Servlet Code===
public class Upload extends HttpServlet {
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
#SuppressWarnings("deprecation")
#Override
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
BlobKey blobKey = blobs.get("myFile");
}
}
Does anyone know how I can incorporate " blobstoreService.createUploadUrl("/upload")" into the servlet so that I can perform curl requests as such:
curl -XPOST http://localhost:8888/upload -F "myFile=#image.jpg"
I'm using the following example from Google's developer page:
https://developers.google.com/appengine/docs/java/blobstore/
This is the way the Blobstore works:
You request a URL to do an upload (provision some resources).
The client uses that URL to post (this means, the request goes to the Blobstore servers and not your application).
The Blobstore servers receive the data, save it, and forward the request to your application.
You get the keys and run your code, then return to the client.
What I'm trying to say is that you must let the Blobstore do it's job, that means you can't have a fixed URL for uploads, you must first ask for a URL to post. This is how the system was designed.
So you'll have to make 2 curl calls, one to request the url, then use that to post, no other way around it.
Of course, it's not as sexy or simple, but other solutions would be complicated and even expensive.
I am developing an app-engine connected android project using the eclipse plugin. When I upload an image to the blobstore, how do I make it callback an endpoint method? I find great posts here that can be used as reference to understand my question better (if you need to).
using blobstore with google cloud endpoint and android
Saving blobs with Google Endpoint
So really, I want to know how to make the callback url an endpoint method such as saveAnimalData below (I stole from referenced link)
#ApiMethod(name = "saveAnimalData", httpMethod = HttpMethod.POST)
public String saveAnimalData(AnimalData request) throws Exception {
}
You should be able to use
https://appid.appspot.com/_ah/api/apiname/version/saveAnimalData
As your final destination url when calling. blobstoreService.createUrl(destination) .
Just bear in mind that the request here is not your original submission. GAE will first call an internal URL (the one created by the blobstoreservice), store the blob and then call your destination URL so whatever info you send will be lost before reaching your endpoint (eg AnimalData will be null)
I am trying to implement a very basic functionality of uploading images from Android,iPhone and web clients to the google app engine. I did an initial version of the implementation thanks to this blog:
However there always seems to be a 2 step process to uploading an image:
Get the initial upload URL to POST to using the createUploadUrl(). I am attaching the fragment of code which I use :
public class CreateUploadUrl extends HttpServlet {
#Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
String uploadURL = blobstoreService.createUploadUrl("/image/uploadImage");
resp.setContentType("text/plain");
resp.getWriter().println(uploadURL);
}
}
POST the image using the URL which you just "got"
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
BlobKey blobKey = ParameterExtractor.getBlobParameter(req, "blob-key", blobstoreService);
if (blobKey == null) {
log.info("blob Id is null. POST failed");
} else {
log.info("ze business logic");
}
}
My question is if it is possible to do it in one step since right now all clients need to do a http GET to get the upload URL and then a http POST to POST the image.
Is it not possible to just do one Http POST with a predefined URL.
Thanks
Rajat
This is possible, with limitations. You can bypass the UploadUrl mechanism by creating blobs directly in your servlet using the (currently experimental) createNewBlobFile API. In your mobile app(s) create an HTTP request encoded as multipart/form-data, and teach your servlet how to decode such a thing (consult e.g. How to upload files in JSP/Servlet?). Be aware that HTTP requests are limited to 32MB; with form encoding the amount of binary data you can upload will be less than that.
Sure you can do it with single POST. For example you have user that have an id. This user select image and you send in POST image data and user data on client side.
On server side (GAE) you have url for image uploding (your_host/imageUpload) and server or Spring controller that read data from request and write it to Blobstore.