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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:55:03+00:00 2026-05-26T15:55:03+00:00

i need to upload audio file(or any File) in server. i have asp.net server

  • 0

i need to upload audio file(or any File) in server. i have asp.net server and refer this code but as per my doubt it is code of PHP server uploading.but i need to do in asp.net. so what is the changes to apply ?

one more thing is url liook like this :: http://xyz/MRESC/images/CustomizeActivity/193/ so its not store in Database it store in directory

Update ::

package com.upload;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class HttpFileUploader extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     HttpURLConnection connection = null;
     DataOutputStream outputStream = null;
     DataInputStream inputStream = null;

     //String pathToOurFile = "/sdcard/audiometer/shanesh1599870.mp3";
     String pathToOurFile = "http://www.deviantart.com/download/78789749/Gohan_Jr__by_android_1.jpg";
     //String urlServer = "http://asd/MRESC/images/CustomizeActivity/193/";
     upLoad2Server(pathToOurFile);
 }



 public static int upLoad2Server(String sourceFileUri) {
      String upLoadServerUri = "http://xyz/MRESC/images/CustomizeActivity/193/";
      // String [] string = sourceFileUri;
      String fileName = sourceFileUri;

      HttpURLConnection conn = null;
      DataOutputStream dos = null;
      DataInputStream inStream = null;
      String lineEnd = "\r\n";
      String twoHyphens = "--";
      String boundary = "*****";
      int bytesRead, bytesAvailable, bufferSize;
      byte[] buffer;
      int maxBufferSize = 1 * 1024 * 1024;
      String responseFromServer = "";

      File sourceFile = new File(sourceFileUri);
      if (!sourceFile.isFile()) {
       return 0;
      }
      int serverResponseCode = 0;
    try { // open a URL connection to the Servlet
       FileInputStream fileInputStream = new FileInputStream(sourceFile);
       URL url = new URL(upLoadServerUri);
       conn = (HttpURLConnection) url.openConnection(); // Open a HTTP  connection to  the URL
       conn.setDoInput(true); // Allow Inputs
       conn.setDoOutput(true); // Allow Outputs
       conn.setUseCaches(false); // Don't use a Cached Copy
       conn.setRequestMethod("POST");
       conn.setRequestProperty("Connection", "Keep-Alive");
       conn.setRequestProperty("ENCTYPE", "multipart/form-data");
       conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
       conn.setRequestProperty("uploaded_file", fileName);
       dos = new DataOutputStream(conn.getOutputStream());

       dos.writeBytes(twoHyphens + boundary + lineEnd);
       dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""+ fileName + "\"" + lineEnd);
       dos.writeBytes(lineEnd);

       bytesAvailable = fileInputStream.available(); // create a buffer of  maximum size
       Log.i("Huzza", "Initial .available : " + bytesAvailable);

       bufferSize = Math.min(bytesAvailable, maxBufferSize);
       buffer = new byte[bufferSize];

       // read file and write it into form...
       bytesRead = fileInputStream.read(buffer, 0, bufferSize);

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

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

       // Responses from the server (code and message)
       serverResponseCode = conn.getResponseCode();
       String serverResponseMessage = conn.getResponseMessage();

       Log.i("Upload file to server", "HTTP Response is : " + serverResponseMessage + ": " + serverResponseCode);
       // close streams
       Log.i("Upload file to server", fileName + " File is written");
       fileInputStream.close();
       dos.flush();
       dos.close();
      } catch (MalformedURLException ex) {
       ex.printStackTrace();
       Log.e("Upload file to server", "error: " + ex.getMessage(), ex);
      } catch (Exception e) {
       e.printStackTrace();
      }
    //this block will give the response of upload link
      try {
       BufferedReader rd = new BufferedReader(new InputStreamReader(conn
         .getInputStream()));
       String line;
       while ((line = rd.readLine()) != null) {
        Log.i("Huzza", "RES Message: " + line);
       }
       rd.close();
      } catch (IOException ioex) {
       Log.e("Huzza", "error: " + ioex.getMessage(), ioex);
      }
      return serverResponseCode;  // like 200 (Ok)

     } // end upLoad2Server


}

Permission ::

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
  • 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-26T15:55:04+00:00Added an answer on May 26, 2026 at 3:55 pm

    To upload a file on server I don’t think so for asp .net and PHP server have a different code on android.

    Just check your server side script. For android both are treated as a server (either a asp .net or PHP). 
    

    I don’t know PHP or asp .net but take a look at these examples,

    1. How to upload a file using Java HttpClient library working with PHP – strange problem

    2. HTTP Post multipart file upload in Java ME

    3. Upload image using POST, php and Android

    4. Java Swing File upload with Php on the server

    5. http://www.tizag.com/phpT/fileupload.php

    In these, there are some example for java swing or java ME but I think just use the logic for upload file from java and then take look at how they handle on server side with php script.

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

Sidebar

Related Questions

I need to upload a file from the client to an asp.net page. The
I need to upload a given image using Amazon S3 I have this PHP:
I have a need to upload only modified parts of the file back to
i need to play audio online in asp.net website My requirement is users will
I need to map various video and audio file types that can be upload
I have a site based on asp.net mvc on windows hosting. Now I need
I need to upload a file (in this case a csv file) and load
I need to upload a local file to server with javascript/AJAX. The problem is
I need to upload the photo of a user with his details from asp.net
i need to upload file without using a form. i need to do this

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.