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

  • SEARCH
  • Home
  • 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 9051427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:54:08+00:00 2026-06-16T12:54:08+00:00

I have been working on Google app engine since 3 days and finally encountered

  • 0

I have been working on Google app engine since 3 days and finally encountered this issue that I am not able to resolve..Did lot of research but could find anything convincing. M

After setting up my Google app Engine account, When I call my application url “my-app-id.appspot.com/myservlet” , the simple Servlet on GAE is able to write .txt file in my Google bucket . Code snippet for the same is here:

 fetchurl.java 

             DefaultHttpClient hc=new DefaultHttpClient();
             ResponseHandler <String> res=new BasicResponseHandler();
             HttpGet postMethod=new HttpGet("http://my-app-id.appspot.com/uploadservlet");

             String response=hc.execute(postMethod,res);

uploadservlet.java

  An example @ Complete Sample App at this link:
  https://developers.google.com/appengine/docs/java/googlestorage/overview

Now My problem is when I send some file through POST method using multi-part , the Servlet @ app engine doesnt work and I get error message “Filenotfound” in eclipse .

.java file at Android side

  urlString = "http://my-app-id.appspot.com/uploadservlet";
  URL url = new URL(urlString);

             // Open a HTTP connection to the URL
             conn = (HttpURLConnection) url.openConnection();
             conn.setConnectTimeout(90000);

             // Allow Inputs
             conn.setDoInput(true);

             // Allow Outputs
             conn.setDoOutput(true);

             // Don't use a cached copy.
             conn.setUseCaches(false);

             // Use a post method.
             conn.setRequestMethod("POST");

             isOK = true;

             conn.setRequestProperty("Connection", "Keep-Alive");

             conn.setRequestProperty("Content-Type",
                     "multipart/form-data;boundary=" + boundary);

             DataOutputStream dos = new DataOutputStream(conn.getOutputStream());


            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=param1;filename="
                            + param1 + "" + lineEnd);
            dos.writeBytes(lineEnd);
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            Log.e(Tag, "Param1 are written");

            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=param2;filename="
                            + param2 + "" + lineEnd);
            dos.writeBytes(lineEnd);
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            Log.e(Tag, "Param2 are written");



            FileInputStream fileInputStream = new FileInputStream(new File(
                    path));
            dos.writeBytes(twoHyphens + boundary + lineEnd);
            dos.writeBytes("Content-Disposition: form-data; name=uploadedfile;filename="
                         + path + "" + lineEnd);
            dos.writeBytes(lineEnd);

            Log.e(Tag, "Headers are written");

             // create a buffer of maximum size

             int bytesAvailable = fileInputStream.available();
             int maxBufferSize = 1000;
             // int bufferSize = Math.min(bytesAvailable, maxBufferSize);
             byte[] buffer = new byte[bytesAvailable];

             // read file and write it into form...

             int bytesRead = fileInputStream.read(buffer, 0, bytesAvailable);

             while (bytesRead > 0) 
             {
                 dos.write(buffer, 0, bytesAvailable);
                 bytesAvailable = fileInputStream.available();
                 bytesAvailable = Math.min(bytesAvailable, maxBufferSize);
                 bytesRead = fileInputStream.read(buffer, 0, bytesAvailable);
             }

             // send multipart form data necesssary after file data...
             //dos.writeBytes(lineEnd);
             dos.writeBytes(twoHyphens + boundary + lineEnd);
             dos.writeBytes(lineEnd);
             dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

I am wondering if this approach is even right. If not what are another solutions..I also looked at blobstorage but it does the same , writing file to bucket not uploading..Please help me guys…Anything would great and appreciated!!!

 Servlet code to handle file upload and save to Google storage--

 @MultipartConfig   
 @SuppressWarnings("serial")
   public class SecondtrygoogleServlet extends HttpServlet 
   {
public static String BUCKETNAME = "androidbucket";
public static String FILENAME = "shikhatry.txt";

private static final long serialVersionUID = 1L;


private static final int THRESHOLD_SIZE = 1024 * 1024 * 3; // 3MB
private static final int MAX_FILE_SIZE = 1024 * 1024 * 40; // 40MB
private static final int REQUEST_SIZE = 1024 * 1024 * 50; // 50MB



public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException 
{
    // checks if the request actually contains upload file
    if (!ServletFileUpload.isMultipartContent(request)) {
        // if not, we stop here
        return;
    }

    response.setContentType("text/plain");
    response.getWriter().println("Hello, test1 world");

    // configures some settings
    DiskFileItemFactory factory = new DiskFileItemFactory();
    factory.setSizeThreshold(THRESHOLD_SIZE);
    factory.setRepository(new File(System.getProperty("java.io.tmpdir")));

    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setFileSizeMax(MAX_FILE_SIZE);
    upload.setSizeMax(REQUEST_SIZE);
    java.io.PrintWriter out = response.getWriter( );

    try {
            // parses the request's content to extract file data
            List<?> formItems = upload.parseRequest(request);
            out.println("Number of fields: " + formItems.size());
            Iterator<?> iter = formItems.iterator();


            // iterates over form's fields
            while (iter.hasNext()) 
            {
                out.println("Inside while loop");
                FileItem item = (FileItem) iter.next();
                // processes only fields that are not form fields
                if (!item.isFormField()) 
                {

                    String temp = item.getFieldName();
                    out.println("Parameter Name"+temp);

                    if(temp.equals("uploadedfile"))
                    {
                        String fileName = new File(item.getName()).getName();
                        FILENAME = fileName+".txt";
                        out.println("Filename"+fileName);


                        FileService fileService = FileServiceFactory.getFileService();
                        GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder()
                        .setBucket(BUCKETNAME)
                        .setKey(FILENAME)
                        .setMimeType("text/html") //audio/mp3 text/html
                        .setAcl("public_read")
                        .addUserMetadata("myfield1", "my field value");


                     AppEngineFile writableFile =
                         fileService.createNewGSFile(optionsBuilder.build());

                     // Open a channel to write to it
                     boolean lock = false;
                     FileWriteChannel writeChannel =
                         fileService.openWriteChannel(writableFile, lock);


                     // Different standard Java ways of writing to the channel
                     // are possible. Here we use a PrintWriter:

                     InputStream inputStream = item.getInputStream();
                     int readBytes = 0;
                     byte[] buffer = new byte[10000];



                     while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) 
                     {
                        writeChannel.write(ByteBuffer.wrap(buffer));

                     }

                     inputStream.close();

                     writeChannel.closeFinally();
                     response.getWriter().println("Done writing...");

                }
                else if(temp.equals("param1"))
                {
                    out.println("Inside param1");
                    //String param1Val = new File(item.getName()).getName();                        
                    //BUCKETNAME = param1Val;
                }
                else if(temp.equals("param2"))
                {
                    out.println("Inside param2");
                    //String param2Val = new File(item.getName()).getName();

                    //BUCKETNAME = param2Val;


                }
            }
        }
        request.setAttribute("message", "Upload has been done successfully!");
    } catch (Exception ex) {
        request.setAttribute("message", "There was an error: " + ex.getMessage());
    }


}
  • 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-16T12:54:10+00:00Added an answer on June 16, 2026 at 12:54 pm

    Options are:

    a. Use createUploadURL with a form to upload large files, or

    b. Use your method and then decode parse the upload and write to the blobstore yourself in the servlet (files would need to be less than 32MB), or

    c. Use Google Cloud Storage API to write directly to GCS and then post the uploaded file names to your App.

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

Sidebar

Related Questions

I have a google app engine app that has been running for some time,
I have been working on the app engine for some time, and this problem
I have been working on a website with Google App Engine for the past
I am working on a Google App Engine application, and have been facing some
I have been working on this app for at least 3-4 months and just
I've been working with Google App Engine and I'm running into some slow performance
I have been using Google app engine for ~2 years now and love it.
I have been working on this Tab View and I finally got it working
I've been working on an Android App that has already been published to Google
I have been working with the app engine for a few weeks and now

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.