0

Hi Iam trying to upload an image to server. But it is giving me IOException while uploading the image, which means the exception part is always get running. Pls help me how to resolve this problem.

Iam using the below code:

try {
                UpurlString = "http:/xxxxx/xxx/UpImage.php";
                length = fileInputStream.available();               
                //connectHTTP(UpurlString);
                url = new URL(UpurlString);
                conn = (HttpURLConnection) url.openConnection();                
                conn.setDoInput(true);
                conn.setDoOutput(true);
                conn.setUseCaches(false);
                conn.setRequestMethod("POST");
                conn.setRequestProperty("Connection", "Keep-Alive");
                conn.setRequestProperty("Content-Type",
                        "multipart/form-data;boundary=" + boundary);
                dos = new DataOutputStream(conn.getOutputStream());
                dos.writeBytes(twoHyphens + boundary + lineEnd);
                Log.e("FilenameCheck",filename);
                dos.writeBytes("Content-Disposition: form-data; name=\"userfile\";filename=\""
                        + filename + "" + lineEnd);
                dos.writeBytes(lineEnd);
                buffer = new byte[8192];
                bytesRead = 0;
                while ((bytesRead = fileInputStream.read(buffer)) > 0) {
                    dos.write(buffer, 0, bytesRead);
                    sentData += bytesRead;
                }
                dos.writeBytes(lineEnd);
                dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);               
                fileInputStream.close();
                dos.flush();
                dos.close();                        
                    inStream = new DataInputStream(conn.getInputStream());
                    while ((strResponse = inStream.readLine()) != null) {
                        Log.e("Response", strResponse);
                        /*if (strResponse.equalsIgnoreCase("The file " + filename
                                + " has been uploaded")) {                          
                        } else {                            
                        }*/
                    }
                    inStream.close();               
            } catch (IOException ioex) {
                Log.e("Debug", "error: " + ioex.getMessage(), ioex);
            }
3
  • Please add the stacktrace. Commented May 29, 2014 at 13:15
  • no error. only the exception part is running.05-29 09:17:31.728: E/Debug(11629): error: http:/xxxxx/xxx/UpImage.php Commented May 29, 2014 at 13:18
  • is there a / in the url http:/webleads.usawebdept.com/IPhone/leadImage.php after http: Commented May 29, 2014 at 13:19

1 Answer 1

1

There is a / in the url http:/webleads.usawebdept.com/IPhone/leadImage.php after http

Sign up to request clarification or add additional context in comments.

2 Comments

I have add the command as answer. please accept it as solution.
can u tell me ur gmail id? i have some more doubts in android.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.