Transferring base64-encoded images to a Google Cloud endpoint using a content management system

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

Answer №1

It appears that there might be a bug within the API configuration generation process due to inadequate information provided. In Endpoints, only JSON objects are permitted as resources, not text primitives. To address this issue, I recommend creating a class Request { Blob image; } in standard Java format and utilizing this structure instead of generating a new Blob. Subsequently, update the resource to accept the Request type:

@ApiMethod(name = "storeItemFromJs", path="itembean/store/js")
public Entity storeItemFromJs(..., Request request)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Node.js to extract information from a web application that necessitates logging in

I find myself in a situation where I need to gather data from a webpage that does not have an API available. The scenario is as follows: In order to access the page data, one must first log in (usually resulting in the creation of session storage/cook ...

Reasons I should consider using WebDriver over ChromeDriver

I am currently involved in a project where we specifically require our tests to be run on the Chrome browser exclusively, with no need for any other browsers. Instead of WebDriver driver = new ChromeDriver(); Is it possible to use ChromeDriver driver = n ...

Why is it that masonry is typically arranged in a single column with overlapping

I have been using the appended function in my code to add elements to a masonry instance that has already been initialized. However, I am facing an issue where all the tiles are being laid out in a single column and some of them are overlapping each oth ...

Tips on stopping slideToggle from opening and closing when clicked for the first time

When using the slideToggle function, I'm encountering an issue where the content div briefly shows on the first click but then immediately slides closed. Subsequent clicks work as expected and slide open correctly. This is the Jquery script I have be ...

Experiencing issues in retrieving data post-login using ASP.net session key method

I have developed a website using AngularJS for the front-end and Windows webforms for the back-end. I believe that the Authorization process is carried out using ASP.net Session Key. The approach involves creating an AngularJS Post method for "login" foll ...

Separating vendor and application code in Webpack for optimized bundling

Recently, I created a React+Webpack project and noticed that it takes 60 seconds to build the initial bundle, and only 1 second to append incremental changes. Surprisingly, this is without even adding my application code yet! It seems that the node_modules ...

Create a Buffer that includes all the characters of the alphabet when converted to

My current project involves using Node.js to generate secure, random tokens. Here is a snippet of the code I'm using: crypto.randomBytes(32).toString("hex"); // dd89d6ab1a7196e8797c2da0da0208a5d171465a9d8e918d3b138f08af3e1852 Although this method wo ...

Create a WebGL object remotely on the server

Exploring potential project ideas, I was curious to see if it's feasible to produce a WebGL scene or object on the server side and then have it rendered on the client. The motivation behind this is that generating a scene typically involves utilizing ...

A guide on transforming JSON data into HTML using Rails

I'm struggling with parsing JSON on a webpage. My webpage is designed with circles, where clicking on a circle triggers a call to the controller to retrieve specific information from a database and display it as graphs and text. The issue I'm fa ...

What are the steps to encapsulate an Android app within a React Native component, effectively creating a complete view?

I'm currently working on integrating my existing android native app into a React Native application with react-navigation. I'm trying to figure out how I can wrap the android app in a component and call it within the StackNavigator like this: co ...

Discovering whether WiFi networks are open to the public or require a secure password can be achieved through

Could someone please provide guidance on filtering secured or public hotspots using the Android WiFi API or Android SDK? ...

The submission of the form using AJAX is currently experiencing issues

My current issue involves ajax not functioning as intended. I have a form that is being submitted through ajax to my php file for the purpose of updating my database. The database update is successful, but there seems to be a problem with the ajax function ...

Basket removal with smooth sliding animation

I need help with adding a sliding animation to my application when removing an element by clicking the 'remove from basket' button. I have tried several methods but haven't been successful. Can anyone assist me in incorporating the animation ...

Issue with draggable div containing gmap not functioning on mobile browsers

Is it possible to make a specific div draggable without dragging the content inside, such as a gmap widget? I have tried implementing this functionality in my code and it works on a computer browser but not on a mobile browser. Here is the simplified versi ...

An unforeseen error occurred while constructing symbols (rebuildModuleMaps)

During the process of building gradle in Android Studio, I encountered a NullPointerException error. This error came unexpectedly as everything was working fine before. The complete error message is: NullPointerException: Unexpected exception during symbo ...

The designated function name can be either "onButtonClick" or "onClickButton"

I am a Japanese developer working on web projects. Improving my English language skills is one of my goals. What would be the correct name for a function that indicates "when a button has been clicked"? Is it "onButtonClick"? Maybe "onClickButton"? Co ...

Error encountered while trying to display content in the rendering area

const Pages = () => { return ( <> <Box display="flex"> {window.location.pathname === "/profile" ? undefined : <Sidebar />} <Box flex={3}> <Navbar /> <Routes> {/* Cont ...

Tips for preserving the status of a sidebar

As I work on developing my first web application, I am faced with a navigation challenge involving two menu options: Navbar Sidebar When using the navbar to navigate within my application, I tend to hide the sidebar. However, every ti ...

Incorporate a `fresh Audio` element into my redux repository

I'm attempting to include a new Audio element in my redux store. This is how my reducer appears: export const songsReducer = (state = {}, action) => { switch (action.type) { case "PLAY_SONG": return { ...state ...

Initiate server side subroutine once JavaScript timer completes

The timer for the online exam countdown is created using JavaScript. If the timer reaches 0:0:00, it alerts the user and proceeds to the next webpage as shown below: function myTimer(startVal,interval,outputId, dataField){ ... var current = this.value; ...