Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy there's broken pipe in my dos.write(buffer, 0, bufferSize)?
    text
    copied!<p>I'm having a big problem in writing in my dos.write it gives me a broken pipe and I don't know how to fix it. Can anyone suggest the proper way of handling this type of error. I search to the web and says the problem is the connection but when I trying to remove the code where I write the file in outputStream the other write bytes in outputStream is working. Please help me thanks..</p> <p><strong>----Here's my Code----</strong></p> <pre><code> FileInputStream stream = new FileInputStream(mFile); bytesAvailable = stream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; int bufferlength = buffer.length; // read file and write it into form... bytesRead = stream.read(buffer, 0, bufferSize); String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "-------------------------acebdf13572468";// random data String paramName = mFile.getName(); String param4 = samplefile; Log.i("FileName", paramName); URL url = new URL(urlString); // Open a HTTP connection to the URL conn = (HttpURLConnection) url.openConnection(); // Allow Inputs conn.setDoInput(true); // Allow Outputs conn.setDoOutput(true); // Don't use a cached copy. conn.setUseCaches(false); // Use a post method. conn.setRequestMethod("POST"); String encoded = Base64.encodeToString((_username+":"+_password).getBytes(),Base64.NO_WRAP); conn.setRequestProperty("Authorization", "Basic "+encoded); //conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary); conn.setChunkedStreamingMode(bufferSize); conn.connect(); dos = new DataOutputStream( conn.getOutputStream() ); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name=\"fieldNameHere\";filename=\"" + paramName + "\"" + lineEnd); // filename is the Name of the File to be uploaded dos.writeBytes("Content-Type: " + mimetype + lineEnd); dos.writeBytes(lineEnd); dos.write(buffer, 0, bufferSize); Log.i("Run at: ", "Normal File"); var = bufferSize; Log.i("BytesAvailable", String.valueOf(bytesAvailable)); Log.i("bufferSize", String.valueOf(bufferSize)); Log.i("Bytes Read", String.valueOf(bytesRead)); Log.i("buffer", String.valueOf(buffer.length)); dos.writeBytes(lineEnd); dos.writeBytes(twoHyphens + boundary + lineEnd); // Send parameter #chunks dos.writeBytes("Content-Disposition: form-data; name=\"chunk\"" + lineEnd); dos.writeBytes(lineEnd); dos.writeBytes("0" + lineEnd); dos.writeBytes(twoHyphens + boundary + lineEnd); // Send parameter #name dos.writeBytes("Content-Disposition: form-data; name=\"name\"" + lineEnd); dos.writeBytes(lineEnd); dos.writeBytes(myUUID + lineEnd); Log.i("name: ", paramName); Log.i("filename: ", param4); Log.i("FileSize: ", String.valueOf(bytesAvailable)); // send multipart form data necesssary after file data... dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); // close streams FileUploadresponseCode = String.valueOf(conn.getResponseCode()); FileUploadresponseMessage = conn.getResponseMessage(); Log.i("DOS: ", String.valueOf(dos.size())); Log.i("Response Code: ", FileUploadresponseCode); Log.i("Response Message: ", FileUploadresponseMessage); is = conn.getInputStream(); // retrieve the response from server int ch; StringBuffer b =new StringBuffer(); while( ( ch = is.read() ) != -1 ){ b.append( (char)ch ); } String s = b.toString(); Log.i("Response",s); if (!FileUploadresponseCode.equals("200")){ FileUploadresponseMessage = conn.getResponseMessage(); TypeOfError = "Status Code"; return false; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload