From ab358e7dbff9a30d40801f199427356e3a8d9071 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Thu, 13 Aug 2020 22:12:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhttp=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=EF=BC=8C=E6=9C=AC=E5=9C=B0md5=E5=92=8C?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=9A=84=E6=9C=8D=E5=8A=A1=E7=9A=84=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6md5=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20https://github.com/AriaLyy/Aria/issues/730?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DEV_LOG.md | 1 + .../http/upload/HttpUThreadTaskAdapter.java | 30 ++++++++----------- .../core/download/SingleTaskActivity.java | 2 +- .../core/upload/HttpUploadActivity.java | 11 ++++--- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/DEV_LOG.md b/DEV_LOG.md index c452717a..cc252064 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -5,6 +5,7 @@ - 修复同一个url地址的任务提示路径冲突的问题 - 修复m3u8任务地址错误时,无法删除实体的问题 https://github.com/AriaLyy/Aria/issues/712 - 修复m3u8gzip的问题,https://github.com/AriaLyy/Aria/issues/639 + - 修复http表单上传,本地md5和上传的服务的的文件md5不一致的问题 https://github.com/AriaLyy/Aria/issues/730 - 增加m3u8密钥下载地址转换器增加ts列表的url地址 https://github.com/AriaLyy/Aria/issues/718 - 增加现在http文件下载将使用HEAD请求获取文件大小,配置文件增加 - 增加允许不使用apt直接通过实现监听器来回调下载进度更新,该功能由[chenfei0928](https://github.com/chenfei0928)提交,感谢他的pr。如果注解不生效,只需要实现`DownloadListener`接口便可 diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpUThreadTaskAdapter.java b/HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpUThreadTaskAdapter.java index 4b496236..5c69904d 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpUThreadTaskAdapter.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/upload/HttpUThreadTaskAdapter.java @@ -26,6 +26,7 @@ import com.arialyy.aria.util.CommonUtil; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; @@ -75,7 +76,6 @@ final class HttpUThreadTaskAdapter extends BaseHttpThreadTaskAdapter { mHttpConn.setRequestProperty("User-Agent", getUserAgent()); mHttpConn.setConnectTimeout(getTaskConfig().getConnectTimeOut()); mHttpConn.setReadTimeout(getTaskConfig().getIOTimeOut()); - //mHttpConn.setRequestProperty("Range", "bytes=" + 0 + "-" + "100"); //内部缓冲区---分段上传防止oom mHttpConn.setChunkedStreamingMode(getTaskConfig().getBuffSize()); @@ -123,9 +123,10 @@ final class HttpUThreadTaskAdapter extends BaseHttpThreadTaskAdapter { } private String getContentType() { - return (mTaskOption.getHeaders() == null || TextUtils.isEmpty( - mTaskOption.getHeaders().get("Content-Type"))) ? "multipart/form-data" - : mTaskOption.getHeaders().get("Content-Type"); + //return (mTaskOption.getHeaders() == null || TextUtils.isEmpty( + // mTaskOption.getHeaders().get("Content-Type"))) ? "multipart/form-data" + // : mTaskOption.getHeaders().get("Content-Type"); + return "multipart/form-data"; } private String getUserAgent() { @@ -176,23 +177,23 @@ final class HttpUThreadTaskAdapter extends BaseHttpThreadTaskAdapter { FileInputStream inputStream = new FileInputStream(uploadFile); byte[] buffer = new byte[4096]; - int bytesRead; - while ((bytesRead = inputStream.read(buffer)) != -1) { - progress(bytesRead); - mOutputStream.write(buffer, 0, bytesRead); + int bytesLen; + while ((bytesLen = inputStream.read(buffer)) != -1) { + mOutputStream.write(buffer, 0, bytesLen); + progress(bytesLen); if (getThreadTask().isBreak()) { break; } if (mSpeedBandUtil != null) { - mSpeedBandUtil.limitNextBytes(bytesRead); + mSpeedBandUtil.limitNextBytes(bytesLen); } } mOutputStream.flush(); - //outputStream.close(); //不能调用,否则服务器端异常 inputStream.close(); - writer.append(LINE_END); - writer.flush(); + writer.append(LINE_END).flush(); + // 保证上传的文件和本地的一致,https://www.cnblogs.com/tugenhua0707/p/8975121.html + writer.append(PREFIX).append(BOUNDARY).append(PREFIX).append(LINE_END).flush(); } /** @@ -202,11 +203,6 @@ final class HttpUThreadTaskAdapter extends BaseHttpThreadTaskAdapter { */ private String finish(PrintWriter writer) throws IOException { StringBuilder response = new StringBuilder(); - - writer.append(LINE_END).flush(); - writer.append(PREFIX).append(BOUNDARY).append(PREFIX).append(LINE_END); - writer.flush(); - int status = mHttpConn.getResponseCode(); if (status == HttpURLConnection.HTTP_OK) { diff --git a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java index 0e73526f..5d1d70ef 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java @@ -245,7 +245,7 @@ public class SingleTaskActivity extends BaseActivity { if (task.getKey().equals(mUrl)) { Toast.makeText(SingleTaskActivity.this, getString(R.string.download_success), Toast.LENGTH_SHORT).show(); - ALog.d(TAG, "文件md5: 9886e90f014d462b560dcec9c327bdb7"); + //ALog.d(TAG, "文件md5: 9886e90f014d462b560dcec9c327bdb7"); ALog.d(TAG, "下载完成的文件md5: " + CommonUtil.getFileMD5(new File(task.getFilePath()))); getBinding().pl.setInfo(task.getEntity()); } diff --git a/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java b/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java index f195346a..a8224140 100644 --- a/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java @@ -40,7 +40,8 @@ import java.io.File; public class HttpUploadActivity extends BaseActivity { private static final String TAG = "HttpUploadActivity"; - private final String FILE_PATH = "/mnt/sdcard/QQMusic-import-1.2.1.zip"; + //private final String FILE_PATH = "/mnt/sdcard/QQMusic-import-1.2.1.zip"; + private final String FILE_PATH = "/mnt/sdcard/update.jpg"; //private final String FILE_PATH = // Environment.getExternalStorageDirectory().getPath() + "/Download/QQMusic-import-1.2.1.zip"; private UploadEntity mEntity; @@ -55,9 +56,11 @@ public class HttpUploadActivity extends BaseActivity { Aria.upload(this).getTaskList(); mEntity = Aria.upload(this).getFirstUploadEntity(FILE_PATH); - if (mEntity != null){ - getBinding().pl.setInfo(mEntity); + if (mEntity == null) { + mEntity = new UploadEntity(); + mEntity.setFilePath(FILE_PATH); } + getBinding().pl.setInfo(mEntity); Aria.upload(this).register(); getBinding().pl.setBtListener(new ProgressLayout.OnProgressLayoutBtListener() { @@ -86,7 +89,7 @@ public class HttpUploadActivity extends BaseActivity { option.setAttachment("file"); Aria.upload(HttpUploadActivity.this).load(FILE_PATH) //.setUploadUrl("http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".apk\"}") - .setUploadUrl("http://9.9.9.28:5000/upload/") + .setUploadUrl("http://172.16.0.91:5000/upload/") .ignoreFilePathOccupy() //.setTempUrl("http://192.168.1.6:8080/upload/sign_file/").setAttachment("file") //.addHeader("iplanetdirectorypro", "11a09102fb934ad0bc206f9c611d7933")