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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:58:52+00:00 2026-06-02T01:58:52+00:00

The following is a snippet for uploading files using PHP. I am an Android

  • 0

The following is a snippet for uploading files using PHP. I am an Android developer and I want to upload a file. Which means I have to send a POST request to a URL that contains this script.

What is the parameter name that I should use if I want to upload a file?

PHP

if (file_exists("upload/" . $_FILES["file"]["name"])) {
    echo $_FILES["file"]["name"] . " already exists. ";
} else {
    move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
    echo "https://some.site/upload/" . $_FILES["file"]["name"];
}

When I try cURL, the file is uploaded successfully but when I do it via Java, it fails.

cURL

curl -F file=@call_me_now_2.wav http://some.site/upload/

Java Code

    File f = new File("call_me_now_11.wav");

    HttpPost filePost = new HttpPost("https://some.site/upload/");
    FileEntity fileEntity = new FileEntity(f, "audio/wav");
    filePost.setEntity(fileEntity);

    HttpClient client = new DefaultHttpClient();
    client.execute(filePost, new BasicResponseHandler() {

        @Override
        public String handleResponse(HttpResponse response)
                throws HttpResponseException, IOException {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();

            int c = 0;
            StringBuilder builder = new StringBuilder();
            while((c = content.read()) != -1) {
                builder.append((char) c);
            }
            System.out.println(builder.toString());

            return builder.toString();
        }
    });
  • 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-02T01:58:53+00:00Added an answer on June 2, 2026 at 1:58 am

    Answered by this. But nevertheless an explanation.

    One cannot read a binary file as done (as text). That gives problems with line endings, nul characters, character encodings, and again making it binary.

    One normally would get the InputStream, here content, and stream it out, without first reading all into memory.

    import org.apache.commons.fileupload.util.Streams;
    
    OutputStream out = response.getOutputStream();
    Streams.copy(content, out, false);
    

    Of course on posting a form with file upload, follow the mentioned answer.

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

Sidebar

Related Questions

I have this following snippet in my ANT-buildfile, which reads filenames from a file
I have the following snippet of java code: File directoryToMoveTo = new File(file.getParent()+_TEMP); boolean
I tried using the following snippet code to decode the animated gif file with
I have the following snippet. I want to find the appearance of a ,
I have the following snippet below from my script that's using a WebRequest to
The following HTML snippet submits the file to UploadHandler which is a servlet. Then
The following snippet is not working for me. Basically I want to check if
We have the following snippet. OSStatus createErr = PasteboardCreate(kPasteboardClipboard, &m_pboard); if (createErr != noErr)
I have the following snippet from my code: switch ($extention) { case gif: $src
So I have the following snippet of code: private Nullable<decimal> _excessWages; public decimal ExcessWages

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.