gpt4 book ai didi

java - 上传时 EPIPE(破管)?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:59:15 25 4
gpt4 key购买 nike

我的代码有问题,但我不知道 E 日志报告在哪里

04-08 05:47:46.745: E/Upload Server(20080): Starting  : /storage/sdcard1/Music/Piano (my favourites)/11 Tchaikovsky - The Music Lovers.mp3
04-08 05:47:47.136: E/Upload Server(20080): Connection Error : sendto failed: EPIPE (Broken pipe)

什么是(EPIPE)? ,当我尝试上传图像时,它上传成功但任何其他文件 E Cat 报告(破管)为什么!

这是我的上传代码

   @Override
protected String doInBackground(String... urls) {


String upLoadServerUri = "http://test.com/test.php";
String fileName = this.file_path;
HttpURLConnection connection = null;
DataOutputStream outputStream = null;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;
File sourceFile = new File(fileName);
int sentBytes = 0;
long fileSize = sourceFile.length();
connection = null;


try
{


FileInputStream fileInputStream = new FileInputStream(sourceFile);

Log.e("Upload Server ", "Starting : "+ fileName );

URL url = new URL(upLoadServerUri);
connection = (HttpURLConnection) url.openConnection();


connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setChunkedStreamingMode(1024);
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=\"file[]\";filename=\""+ fileName + "\"" + lineEnd);

outputStream.writeBytes(lineEnd);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];



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

while (bytesRead > 0)
{

if(isCancelled()){

break;
}

sentBytes += bytesRead;

double percentDone = (sentBytes * 1.0) / fileSize * 100;
publishProgress((int)percentDone);

outputStream.write(buffer, 0, bufferSize);

bytesAvailable = fileInputStream.available();

bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}

if(isCancelled()){

fileInputStream.close();
outputStream.flush();
outputStream.close();
Log.e("Upload Server ", "upload Canceled " );
return "canceled";
}

outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
int serverResponseCode = connection.getResponseCode();
fileInputStream.close();
outputStream.flush();
outputStream.close();

if(serverResponseCode == 200)
{
Scanner s;
s = new Scanner(connection.getInputStream());
s.useDelimiter("\\Z");
final String response = s.next();
Log.e("Upload Server ", "Message : " + response);
return response;
}else
{
Log.e("Upload Server ", "Server Code Error : " + serverResponseCode );
return "faild";
}
} catch (final Exception e) {

Log.e("Upload Server ", "Error : " + e.getMessage() );
}

return "falid";
}

请注意在 Android 应用程序中仍然更新 :)我用谷歌搜索了我的问题,我找不到解决方案请帮忙!

最佳答案

'Broken pipe' 表示您已写入已被对等方关闭的连接。

可能您已超出上传大小限制。

您还应该注意,您对 available() 的使用是无效的。 Javadoc 中有一个关于按照您使用它的方式使用它的特定警告。反正你不需要它:

while ((count = in.read(buffer)) > 0)
{
out.write(buffer, 0, count);
}

其中 buffer 是任何合理的大小,例如8192 字节。

关于java - 上传时 EPIPE(破管)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15870631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com