diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java index 7275ebd8..7b88e0d5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java @@ -82,7 +82,8 @@ public abstract class AbsFtpInfoThread { + private static final String TAG = "FtpUploadFtpFileInfoThread"; static final int CODE_COMPLETE = 0xab1; private boolean isComplete = false; @@ -56,12 +58,21 @@ class FtpFileInfoThread extends AbsFtpInfoThread if (ftpFile.getSize() == mEntity.getFileSize()) { isComplete = true; } else { + ALog.w(TAG, "FTP服务器已存在未完成的文件【" + + ftpFile.getName() + + ",size: " + + ftpFile.getSize() + + "】" + + "尝试从位置:" + + ftpFile.getSize() + + "开始上传"); File configFile = new File(CommonUtil.getFileConfigPath(false, mEntity.getFileName())); Properties pro = CommonUtil.loadConfig(configFile); String key = mEntity.getFileName() + "_record_" + 0; + mTaskEntity.isNewTask = false; long oldRecord = Long.parseLong(pro.getProperty(key, "0")); - if (oldRecord != 0) { - //修改本地保存的停止地址为服务器上的真实地址 + if (oldRecord == 0) { + //修改本地保存的停止地址为服务器上对应文件的大小 pro.setProperty(key, ftpFile.getSize() + ""); CommonUtil.saveConfig(configFile, pro); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java index 3e108dcd..8783aaeb 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java @@ -89,7 +89,8 @@ class HttpThreadTask extends AbsThreadTask { addFormField(writer, key, mTaskEntity.formFields.get(key)); } uploadFile(writer, mTaskEntity.attachment, uploadFile); - finish(writer); + mTaskEntity.getEntity().setResponseStr(finish(writer)); + mListener.onComplete(); } catch (Exception e) { e.printStackTrace(); fail(); @@ -167,7 +168,6 @@ class HttpThreadTask extends AbsThreadTask { STATE.isRunning = false; return; } - mListener.onComplete(); STATE.isRunning = false; } @@ -184,6 +184,7 @@ class HttpThreadTask extends AbsThreadTask { writer.close(); int status = mHttpConn.getResponseCode(); + if (status == HttpURLConnection.HTTP_OK) { BufferedReader reader = new BufferedReader(new InputStreamReader(mHttpConn.getInputStream())); String line; @@ -193,10 +194,9 @@ class HttpThreadTask extends AbsThreadTask { reader.close(); mHttpConn.disconnect(); } else { - ALog.w(TAG, "state_code = " + status); - fail(); + ALog.e(TAG, "response msg: " + mHttpConn.getResponseMessage() + ",code: " + status); + // fail(); } - writer.flush(); writer.close(); mOutputStream.close(); diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java index bb485a4c..5196af1b 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -34,7 +34,7 @@ import java.util.Map; class DBConfig { static Map mapping = new HashMap<>(); static String DB_NAME; - static int VERSION = 22; + static int VERSION = 23; static { if (TextUtils.isEmpty(DB_NAME)) { diff --git a/DEV_LOG.md b/DEV_LOG.md index 26aed643..8caf37f3 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -2,6 +2,9 @@ + v_3.3.14 - 修复ftp上传和下载的兼容性问题 - 如果url中的path有"//"将替换为"/" + - 修复http上传成功后,如果服务器没有设置返回码导致上传失败的问题 + - 上传实体UploadEntity增加responseStr字段,http上传完成后,在被`@Upload.onComplete`注解的方法中,可通过`task.getEntity().getResponseStr())`获取服务器返回的数据 + - 如果服务器存在已上传了一部分的文件,用户执行删除该FTP上传任务,再次重新上传,会出现550,权限错误;本版本已修复该问题 + v_3.3.13 - 添加`@Download.onWait、@Upload.onWait、@DownloadGroup.onWait`三个新注解,队列已经满了,继续创建新任务,任务处于等待中,将会执行被这三个注解标志的方法 - app被kill,但是还存在等待中的任务A;第二次重新启动,先创建一个新的任务B,Aria会自动把B放进等待队列中,这时再次创建任务A,会导致重复下载,进度错乱的问题;本版本已修复这个问题 diff --git a/README.md b/README.md index 743a102d..f86ca21f 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Aria有以下特点: [![Download](https://api.bintray.com/packages/arialyy/maven/AriaApi/images/download.svg)](https://bintray.com/arialyy/maven/AriaApi/_latestVersion) [![Download](https://api.bintray.com/packages/arialyy/maven/AriaCompiler/images/download.svg)](https://bintray.com/arialyy/maven/AriaCompiler/_latestVersion) ```java -compile 'com.arialyy.aria:aria-core:3.3.13' -annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.13' +compile 'com.arialyy.aria:aria-core:3.3.14' +annotationProcessor 'com.arialyy.aria:aria-compiler:3.3.14' ``` 如果出现android support,请将 `compile 'com.arialyy.aria:aria-core:3.3.13'`替换为 ``` @@ -103,10 +103,11 @@ protected void onCreate(Bundle savedInstanceState) { ### [更多说明,见WIKI](https://github.com/AriaLyy/Aria/wiki) ### 版本日志 -+ v_3.3.13 - - 添加`@Download.onWait、@Upload.onWait、@DownloadGroup.onWait`三个新注解,队列已经满了,继续创建新任务,任务处于等待中,将会执行被这三个注解标志的方法 - - app被kill,但是还存在等待中的任务A;第二次重新启动,先创建一个新的任务B,Aria会自动把B放进等待队列中,这时再次创建任务A,会导致重复下载,进度错乱的问题;本版本已修复这个问题 - + + v_3.3.14 + - 修复ftp上传和下载的兼容性问题 + - 如果url中的path有"//"将替换为"/" + - 修复http上传成功后,如果服务器没有设置返回码导致上传失败的问题 + - 上传实体UploadEntity增加responseStr字段,http上传完成后,在被`@Upload.onComplete`注解的方法中,可通过`task.getEntity().getResponseStr())`获取服务器返回的数据 [更多版本记录](https://github.com/AriaLyy/Aria/blob/master/DEV_LOG.md) diff --git a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java index 6cf598ba..9fc20cc0 100644 --- a/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java @@ -36,13 +36,9 @@ import java.io.File; */ public class FtpDownloadActivity extends BaseActivity { //private final String URL = "ftp://192.168.1.9:21/下载/AriaPrj.zip"; - //private final String URL = "ftp://192.168.1.9:21/下载/[电影天堂www.dy2018.com]赛车总动员3BD中英双字.mp4"; - //private final String URL = "ftp://h:h@tv.dl1234.com:2199/付岩洞复仇者们05.mkv"; - //private final String URL = "ftp://z:z@dygod18.com:21211/[破晓电影www.poxiao.com]情遇曼哈顿HD国语中字.mkv"; //private final String URL = "ftp://182.92.180.213:21/video/572fed5c2ad48_1024.jpg"; - //private final String URL = "ftp://192.168.1.6:21/download/AriaPrj.zip"; - //private final String URL = "ftp://172.18.104.71:21/upload/AS.zip"; - private final String URL = "ftp://d:d@dygodj8.com:12311/[电影天堂www.dy2018.com]脑火BD中字.mp4"; + private final String URL = "ftp://192.168.1.6:21/download/AriaPrj.zip"; + //private final String URL = "ftp://d:d@dygodj8.com:12311/咖啡风暴HD大陆公映意语中字[飘花www.piaohua.com].mp4"; @Override protected void init(Bundle savedInstanceState) { super.init(savedInstanceState); @@ -65,7 +61,7 @@ public class FtpDownloadActivity extends BaseActivity { } } - @Upload.onWait void onWait(UploadTask task){ + @Upload.onWait void onWait(UploadTask task) { Log.d(TAG, task.getTaskName() + "_wait"); } @@ -76,7 +77,7 @@ public class FtpUploadActivity extends BaseActivity { } @Upload.onTaskStart public void taskStart(UploadTask task) { - Log.d(TAG, "开始上传"); + Log.d(TAG, "开始上传,md5:" + FileUtil.getFileMD5(new File(task.getEntity().getFilePath()))); } @Upload.onTaskResume public void taskResume(UploadTask task) { diff --git a/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java b/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java index 2cd63cc8..92089de2 100644 --- a/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java @@ -22,11 +22,13 @@ import butterknife.OnClick; import com.arialyy.annotations.Upload; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.upload.UploadTask; +import com.arialyy.frame.util.FileUtil; import com.arialyy.frame.util.show.L; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; import com.arialyy.simple.databinding.ActivityUploadBinding; import com.arialyy.simple.widget.HorizontalProgressBarWithNumber; +import java.io.File; /** * Created by Aria.Lao on 2017/2/9. @@ -35,7 +37,7 @@ public class HttpUploadActivity extends BaseActivity { private static final String TAG = "HttpUploadActivity"; @Bind(R.id.pb) HorizontalProgressBarWithNumber mPb; - private static final String FILE_PATH = "/mnt/sdcard/360sicheck.txt"; + private static final String FILE_PATH = "/mnt/sdcard/test.txt"; @Override protected int setLayoutId() { return R.layout.activity_upload; @@ -48,12 +50,11 @@ public class HttpUploadActivity extends BaseActivity { } @OnClick(R.id.upload) void upload() { - Aria.upload(HttpUploadActivity.this) - .load(FILE_PATH) - .setUploadUrl( - "http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".txt\"}") - .setAttachment("file") - .addHeader("iplanetdirectorypro", "") + Aria.upload(HttpUploadActivity.this).load(FILE_PATH) + //.setUploadUrl( + // "http://lib-test.xzxyun.com:8042/Api/upload?data={\"type\":\"1\",\"fileType\":\".txt\"}") + .setUploadUrl("http://192.168.1.6:8080/upload/sign_file/").setAttachment("file") + //.addHeader("iplanetdirectorypro", "11a09102fb934ad0bc206f9c611d7933") .start(); } @@ -69,7 +70,7 @@ public class HttpUploadActivity extends BaseActivity { } @Upload.onTaskStart public void taskStart(UploadTask task) { - L.d(TAG, "upload start"); + L.d(TAG, "upload start,md5:" + FileUtil.getFileMD5(new File(task.getEntity().getFilePath()))); getBinding().setFileSize(task.getConvertFileSize()); } @@ -93,6 +94,7 @@ public class HttpUploadActivity extends BaseActivity { @Upload.onTaskComplete public void taskComplete(UploadTask task) { L.d(TAG, "上传完成"); + L.d(TAG, "上传成功返回数据(如果有的话):" + task.getEntity().getResponseStr()); getBinding().setSpeed(""); getBinding().setProgress(100); } diff --git a/build.gradle b/build.gradle index 707f22c5..40de7a5e 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.3.13' + publishVersion = '3.3.14' // publishVersion = '1.0.3' //FTP插件 repoName='maven' desc = 'android 下载框架'