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 9250607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:28:58+00:00 2026-06-18T10:28:58+00:00

Am uploading a mutlipart file to Google app engine using the below shown code.

  • 0

Am uploading a mutlipart file to Google app engine using the below shown code. With the help of apache commons file uploader am uploading the file to Google app engine successfully. I want to validate the file size if it is 0 bytes or not. To do this i verified the Google app engine and the apache commons file uploader to check the file size but i got failed. Do we have any methods to find the file size. Kindly suggest me an idea.

My Servlet

ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter;
iter = upload.getItemIterator(request);
while (iter.hasNext()) {
item = iter.next();
String fileName =  item.getName();
String fieldName = item.getFieldName();
if (item.isFormField()) {
String fieldValue = Streams.asString(item.openStream());
}
InputStream is1 = item.openStream();
try {
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile(mime, fileName);
boolean lock = true;
 FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);
 byte[] b1 = new byte[BUFFER_SIZE];
int readBytes1;
while ((readBytes1 = is1.read(b1)) != -1) {
 writeChannel.write(ByteBuffer.wrap(b1, 0, readBytes1));
}
writeChannel.closeFinally();
  • 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-18T10:28:59+00:00Added an answer on June 18, 2026 at 10:28 am

    You need to read the whole is1 input stream into a byte buffer and see it’s length. You can use this snippet:

    public static byte[] getBytes(InputStream is) throws IOException {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    
        int len;
        byte[] data = new byte[10000];
        while ((len = is.read(data, 0, data.length)) != -1) {
            buffer.write(data, 0, len);
        }
    
        buffer.flush();
        return buffer.toByteArray();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code for uploading an multiform/data form with a file upload:
I am uploading a file on server using this code, But I want such
I'm using WordPress and I'm following W3's guide for uploading a file: HTML code:
I've this JavaScript code to upload a file // Uploading - for Firefox, Google
I am using spring 3.0 org.springframework.web.multipart.commons.CommonsMultipartFile for file uploading. i want write down unit
am I uploading this file right? Here is my code: Deleted Code it is
I am periodically uploading a file to AWS Glacier using boto as follows: #
I've written 'fileUpload.tt' and 'Site.pm' to upload file (pasted below). Its uploading file to
Im uploading a file using the following jquery.. function ajaxFileUpload(jobid) { $(#loading) .ajaxStart(function ()
I want to write a jQuery file uploading program, using this plug-in http://aquantum-demo.appspot.com/file-upload Despite

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.