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

The Archive Base Latest Questions

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

i’m not able to post the image to php server. i have the code

  • 0

i’m not able to post the image to php server.
i have the code that i found while searching but my question is that how to pass username, password,module and function name in in the current request.
this is the code that i found on most of the sites.

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

String pathToOurFile = "/data/file_to_send.mp3";
String urlServer = "http://192.168.1.1/handle_upload.php";
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary =  "*****";

int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;

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();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];

// Read file
bytesRead = fileInputStream.read(buffer, 0, bufferSize);

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

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
}

i’m getting stuck here..any help is appreciated
Thanks

  • 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-13T22:36:27+00:00Added an answer on June 13, 2026 at 10:36 pm
    public static String UplaodData(byte[] data , String text, String id, boolean personalCheck, boolean privateCheck, String  ImageName, boolean isClaimNote, String url, String percentage, boolean showProgress)
    {
        HttpURLConnection connection    = null;
        DataOutputStream outputStream   = null;
        DataInputStream  inputStream    = null;
    
    
        //String claimId = ClaimList.claimId;
    
        String noteType = null;
        String isImageFile = null;
    
        String Responce                 =  "";
        String urlServer                = url;
        String lineEnd                  = "\r\n";
        String twoHyphens               = "--";
        String boundary                 = "*****";
        System.out.println("Value of note type----------------------- "+noteType);
        try
        {
    
            URL url1 = new URL(urlServer);
            connection = (HttpURLConnection) url1.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() );
            if (data != null)
            {
                outputStream.writeBytes(twoHyphens + boundary + lineEnd);
                outputStream.writeBytes("Content-Disposition: form-data;  Content-type: image/png; name=\"attachment\"; filename=\""+ImageName+"\"" + lineEnd);
                outputStream.writeBytes(lineEnd);
                outputStream.write(data, 0, data.length);
                outputStream.writeBytes(lineEnd);
            }
    
            if(isClaimNote){
                outputStream.writeBytes(twoHyphens + boundary + lineEnd);
                outputStream.writeBytes("Content-Disposition: form-data; name=\"claimId\"" + lineEnd);
                outputStream.writeBytes(lineEnd);
                outputStream.writeBytes(id);
                outputStream.writeBytes(lineEnd);
            }else{
                outputStream.writeBytes(twoHyphens + boundary + lineEnd);
                outputStream.writeBytes("Content-Disposition: form-data; name=\"activityId\"" + lineEnd);
                outputStream.writeBytes(lineEnd);
                outputStream.writeBytes(id);
                outputStream.writeBytes(lineEnd);
                if(showProgress){
                    outputStream.writeBytes(twoHyphens + boundary + lineEnd);
                    outputStream.writeBytes("Content-Disposition: form-data; name=\"activityResolution\"" + lineEnd);
                    outputStream.writeBytes(lineEnd);
                    outputStream.writeBytes(percentage);
                    outputStream.writeBytes(lineEnd);
                }
            }
    
            outputStream.writeBytes(twoHyphens + boundary + lineEnd);
            outputStream.writeBytes("Content-Disposition: form-data; name=\"noteType\"" + lineEnd);
            outputStream.writeBytes(lineEnd);
            outputStream.writeBytes(noteType);
            outputStream.writeBytes(lineEnd);
    
            outputStream.writeBytes(twoHyphens + boundary + lineEnd);
            outputStream.writeBytes("Content-Disposition: form-data; name=\"noteText\"" + lineEnd);
            outputStream.writeBytes(lineEnd);
            outputStream.writeBytes(text);
            outputStream.writeBytes(lineEnd);
            outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
    
            outputStream.writeBytes(twoHyphens + boundary + lineEnd);
            outputStream.writeBytes("Content-Disposition: form-data; name=\"isImageFile\"" + lineEnd);
            outputStream.writeBytes(lineEnd);
            outputStream.writeBytes(isImageFile);
            outputStream.writeBytes(lineEnd);
            outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
    
            inputStream  = new DataInputStream( connection.getInputStream());
    
            int serverResponseCode = connection.getResponseCode();
            String serverResponseMessage = "";
    
    
            while ((serverResponseMessage = inputStream.readLine()) != null)
            {
                    Responce   = Responce + serverResponseMessage;
            }
    
            outputStream.flush();
            outputStream.close();
            return Responce;
    
            }
            catch (Exception ex)
            {
                Responce   = ex.toString();
                return Responce;
            }
    }
    
    Above is working code to upload multiparty data, customize this as per you parameter   list
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm trying to create an if statement in PHP that prevents a single post
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.