I am facing a challenge trying to send an image from my content management system (CMS) to my Google Cloud Endpoint for storage in the Google Datastore. The process involves converting the image into a base64 string before sending it to the endpoint. Sending the image works smoothly from my Android application, but encounters an error when attempted from the CMS. This is due to differences in API methods between the Java-based application and the JavaScript-based CMS.
The only supported data types for sending an image to the endpoint are String, Text, or Blob.
Here is a snippet from the method on the CMS responsible for sending the image to the endpoint:
var testApi = gapi.client.itemApi;
var testApiMethod = testApi.storeItemFromJs({
"id" : id,
"name" : name,
"description" : description,
"status" : status,
"contents" : contents,
"resource": {
"image": image
}});
testApiMethod.execute();
The current API method being used utilizes Text for handling the image:
@ApiMethod(name = "storeItemFromJs", path="itembean/store/js")
public Entity storeItemFromJs(@Named("id")String id, @Named("name") String name,
@Named("description") String description,
@Named("status") String status,
@Named("contents") String contents, Text image)
{
// Method implementation here...
}
An attempt to use Blob instead of Text results in an error during project rebuild with no apparent solution. Using String for the image works for shorter strings but fails with longer ones, limiting its usage for images.
Update:
After modifying the code based on saiyr's suggestion, the updated endpoint definition looks like this:
@ApiMethod(name = "storeItemFromJs", path="itembean/store/js")
public Entity storeItemFromJs(@Named("id")String id, @Named("name") String name,
@Named("description") String description,
@Named("status") String status,
@Named("contents") String contents, Request image)
This approach seems to resolve the issue. Any assistance with resolving the 503 error encountered would be greatly appreciated.
Thank you Tom