Java Server Code File input

Is it possible to construct a Java Server Code API endpoint that will accept file content as input, possibly by configuring the Content-Type as “multipart/form-data”, or is “application/json” the only option?

Thanks

Hello @Mark_Moline

Yes, at this moment “application/json” is the only one accepted content-type

Alright thank you.

Is there any possibility of other content-types being usable in the future?

Also in trying to work around this limitation I’ve just found an unexpected problem:

When debugging my server code through CodeRunner I was able to use the following function to get the app ID for the Backendless app through which the code was running:

Backendless.getApplicationId();

However when I deployed the same server code this function is unavailable and I get the following response form the associated API endpoint:

400 - Type:"java.lang.NoSuchMethodError", Description:"'java.lang.String com.backendless.Backendless.getApplicationId()'", ExceptionClass:"ServiceException" {Msg:"none", Cause:"none"}

Is there a reason why this is unavailable when deployed? And is there an alternative mechanism through which I can dynamically get the current Backendless App ID (and also the server code API key) within my server code?

Resolved the second issue. I was able to find and use an updated version of the Backendless .jar that included a new function:

Backendless.getApplicationIdOrDomain()

which deployed and runs successfully.

Hello @Mark_Moline

Unfortunately, there are currently no plans to add the possibility to use other Content-Types.

Regards,
Alexander

Alright.

My use case is that I want to restrict Backendless file access to the server code runner and I want to construct an API handler in my server code that uploads a file to my Backendless app, sends an email that includes that file as an attachment, and then removes the file from my Backendless app.

I’ve currently set up an API handler in my app’s Java server code that accepts as input a base64 encoded file string. The string is decoded, uploaded to Backendless through the Backendless REST file API (not the java client API which only accepts an input of type File and not a byte[]), and email is sent with that file, and then that file is removed.

The above method works for relatively small files but has major issues given the encoding with more than a few megabytes.

Is there a better way that I could solve this problem given the tools and constraints available? My primary constraints are:

  • File access is restricted to only the server code runner
  • Within one server code API endpoint I can accept a file as input and include it as an attachment in an email sent through Backendless messaging.
  • The file does not persist after an email is successfully sent.

Thanks

Hi @Mark_Moline ,

Unfortunately there is no other way to reach your goals beside using base64 encoded strings.

Regards, Andriy