Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9091635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:39:26+00:00 2026-06-16T22:39:26+00:00

In a stateless mobile app I need to upload an image file form a

  • 0

In a stateless mobile app I need to upload an image file form a mobile client to my server which exposes a spring MVC based web layer (Later I will need to execute an OCR process over this image, but this is not relevant at this point).

All the spring MVC file upload examples I’ve seen are based on MultipartFiles which doesn’t suite my needs since they assume a modelAndView existence, but my server is stateless, I don’t use models or views nor http sessions, only pure and simple JSON formatted restful requests.

I wonder what is the best way to do this?

For now, I created a test that sends my images as string to my server (using base64 encoding). Something like:

ClassPathResource myFile= new ClassPathResource("imageName.jpg");
byte[] fileByteArray = Files.readAllBytes(myFile.getFile().toPath());
String imageAsString = Base64.encodeBase64URLSafeString(fileByteArray);

Now I’m sending this imageAsString to my cotroller.
In my controller I can then decode this string back to byte array using something like this:

public static byte[] decodeFile(String fileDataString) {
return Base64.decodeBase64(fileDataString);
}

So in my server I’m now holding a byte array, which is raw data, and I’m not that sure I can do anything with it besides writing it to FileOutputStream. Can someone recommend good practice for uploading an image to my server?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:39:27+00:00Added an answer on June 16, 2026 at 10:39 pm

    Since uploading MultipartFile to a spring MVC web layer requires multiple changes (servlet-context changes, message converters changes, Controller adjustments etc..) and I could not find any complete and sinple tutorial for this process I decided to simply upload my files (images) as a Base64 encoded string. To do this I used org.apache.commons.codec.binary.Base64 which provides the encodeBase64URLSafeString mathod that can encode my file into string and then using decodeBase64 decode it back to the original file content. This way I’m not loosing any data on the way and I’m avoiding any complex changes. The disadvantage of this method is that it requires my clients to encode the files in the exact same way the encodeBase64URLSafeString method does, so I’m quite sure it is not optimal..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

which Stateless bean instance assigned to EJB object to serve the client, when two
I'm making a stateless web service which uses Microsoft SQL Server to read data
I have a stateless session bean with a method which throws an exception (which
Since http is stateless, every request to an app creates a new object. How
My application is a stand-alone Swing client invoking EJB Stateless Session beans thanks to
I came across stateless , a hierarchical state machine framework based on Simple State
I have a stateless session bean and a standalone-java-program acting as a client. The
I'm creating a stateless session bean (the façade) which will be used for managing
Since HTTP is a stateless protocol, when a client makes a number of requests
I have a stateless EJB that acceses my database. I need this bean in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.