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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:41:31+00:00 2026-05-31T21:41:31+00:00

I am uploading a stream to server.But my Input-stream contain a big video file.So

  • 0

I am uploading a stream to server.But my Input-stream contain a big video file.So i want to split it in different Input-stream and then i will send them one by one.

I have gone through a question that TeeOutputStream(i do not how it work in java) in Java for doing this.But it does not exist in android.
Any help much appreciated as usual

Updated

Please donot suggest me manual way.

  • 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-05-31T21:41:32+00:00Added an answer on May 31, 2026 at 9:41 pm

    You do not have to split up the input or output stream.
    You can upload a large file with multipart entity.In Multipart entity there is a class FileEntity which is responsible to upload a file

    I have a code for multipart entity see below code.

    public class uploadFile extends AsyncTask<Void, Void, Boolean> {
            private final ProgressDialog dialog = new ProgressDialog(parentActivity);
    
            protected void onPreExecute() {
                this.dialog.setMessage("Uploading file");
                this.dialog.setCancelable(false);
                this.dialog.show();
            }
    
            @Override
            protected Boolean doInBackground(Void... arg0) {
    
                try {
                    HttpClient httpClient = new DefaultHttpClient();
                    HttpPost postRequest = new HttpPost(URLS.PRESCRIPTION_POST_URL);
                    MultipartEntity reqEntity = new MultipartEntity(
                            HttpMultipartMode.BROWSER_COMPATIBLE);
    
                    reqEntity.addPart("title", new StringBody("This is a title of video file"));
                    try {
                        File f = new File(Environment.getExternalStorageDirectory(), "your file name with extension");
    
                        FileBody body = new FileBody(f);
                        reqEntity.addPart("parameter that server will read", body);
    
                    } catch (Exception e) {
                        reqEntity.addPart("parameter that server will read", new StringBody(""));
                    }
    
                    reqEntity.addPart("description", new StringBody("description"));
    
                    postRequest.setEntity(reqEntity);
                    HttpResponse response = httpClient.execute(postRequest);
    
                    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); 
                    String sResponse; StringBuilder s = new StringBuilder(); 
                    while ((sResponse = reader.readLine()) != null) { 
                        s = s.append(sResponse); 
                    } 
                    Log.v("Response for POst", s.toString());
                    return true;
                } catch (Exception e) {
                    Log.e("MyPharmacyOptions", "Error :: " + e);
                }
                return false;
            }
    
            @Override
            protected void onPostExecute(Boolean result) {
                if (this.dialog.isShowing()) {
                    this.dialog.dismiss();
                }
                if (result) {
                    Toast.makeText(parentActivity,
                            "File uploaded successfully", Toast.LENGTH_LONG)
                            .show();
    
                } else {
                    Toast.makeText(parentActivity, "Your Request not complete",
                            Toast.LENGTH_LONG).show();
                }
            }
        }
    

    To use MultipartEntity you will required a jar file httpmime-4.1.2.jar.

    There is also another alternative of this

    HttpURLConnection connection = null;
    DataOutputStream outputStream = null;
    DataInputStream inputStream = null;
    
    String pathToOurFile = "/sdcard/file_to_send.mp3"; //complete path of file from your android device
    String urlServer = "URL of your server";// complete path of server
    String lineEnd = "\r\n";
    String twoHyphens = "--";
    String boundary =  "*****";
    
    try
    {
    FileInputStream fileInputStream = new FileInputStream(new File(pathToOurFile) );
    
    URL url = new URL(urlServer);
    connection = (HttpURLConnection) url.openConnection();
    
    // Allow Inputs & Outputs
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setUseCaches(false);
    
    // Enable POST method
    connection.setRequestMethod("POST");
    
    connection.setRequestProperty("Connection", "Keep-Alive");
    connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
    
    outputStream = new DataOutputStream( connection.getOutputStream() );
    outputStream.writeBytes(twoHyphens + boundary + lineEnd);
    outputStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + pathToOurFile +"\"" + lineEnd);
    outputStream.writeBytes(lineEnd);
    
    bytesAvailable = fileInputStream.available();
    
    byte []buffer = new byte[4096];
    int read = 0;
    while ( (read = fileInputStream.read(buffer)) != -1 ) {
        outputStream.write(buffer, 0, read);
    }
    
    outputStream.writeBytes(lineEnd);
    outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
    
    // Responses from the server (code and message)
    serverResponseCode = connection.getResponseCode();
    serverResponseMessage = connection.getResponseMessage();
    
    fileInputStream.close();
    outputStream.flush();
    outputStream.close();
    }
    catch (Exception ex)
    {
    //Exception handling
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I am uploading the video file to the server I sending the sample
Im uploading zip file (compressed with winrar) to my server by FileUpload control. On
I want to use Ruby Mechanize to write an auto file uploading script for
I am trying to upload file on HTTP server using POST but when I
I was uploading my file using below code,it works fine but some time it
I'm working on a live photo stream app. Essentially, users will be uploading photos
I want to upload .3gp video files to server via PHP code. I checked
I want to upload a plist file to my server from my iphone app.
Say I want to have a server that can accept 2GB file over network,
I am trying to create a ftp client with uploading a file capability. But

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.