修复http上传成功后,如果服务器没有设置返回码导致上传失败的问题,

pull/330/head
AriaLyy 7 years ago
parent 1cfcfb90b8
commit ebddc510ca
  1. 3
      Aria/src/main/java/com/arialyy/aria/core/common/AbsFtpInfoThread.java
  2. 6
      Aria/src/main/java/com/arialyy/aria/core/common/AbsThreadTask.java
  3. 15
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
  4. 15
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java
  5. 10
      Aria/src/main/java/com/arialyy/aria/core/upload/uploader/HttpThreadTask.java
  6. 2
      Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java
  7. 3
      DEV_LOG.md
  8. 13
      README.md
  9. 10
      app/src/main/java/com/arialyy/simple/download/FtpDownloadActivity.java
  10. 7
      app/src/main/java/com/arialyy/simple/upload/FtpUploadActivity.java
  11. 18
      app/src/main/java/com/arialyy/simple/upload/HttpUploadActivity.java
  12. 2
      build.gradle

@ -82,7 +82,8 @@ public abstract class AbsFtpInfoThread<ENTITY extends AbsEntity, TASK_ENTITY ext
ALog.i(TAG, s);
boolean isExist = files.length != 0;
if (!isExist && !isUpload) {
failDownload("文件不存在,任务链接【" + mTaskEntity.urlEntity.url + "】", false);
failDownload("文件不存在,任务链接【" + mTaskEntity.urlEntity.url + "】,remotePath:" + remotePath,
false);
int i = remotePath.lastIndexOf(File.separator);
FTPFile[] files1;
if (i == -1) {

@ -232,7 +232,11 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY
ALog.w(TAG,
"任务【" + mConfig.TEMP_FILE.getName() + "】thread__" + mConfig.THREAD_ID + "__重试失败,网络未连接");
}
if (mFailNum < RETRY_NUM && needRetry && NetUtils.isConnected(AriaManager.APP)) {
if (mFailNum < RETRY_NUM
&& needRetry
&& NetUtils.isConnected(AriaManager.APP)
&& !STATE.isCancel
&& !STATE.isStop) {
mFailTimer = new Timer(true);
mFailTimer.schedule(new TimerTask() {
@Override public void run() {

@ -18,8 +18,8 @@ package com.arialyy.aria.core.upload;
import android.os.Parcel;
import android.os.Parcelable;
import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.orm.Foreign;
import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.orm.Foreign;
import com.arialyy.aria.orm.Primary;
/**
@ -29,6 +29,19 @@ import com.arialyy.aria.orm.Primary;
public class UploadEntity extends AbsNormalEntity implements Parcelable {
@Primary @Foreign(table = UploadTaskEntity.class, column = "key") private String filePath; //文件路径
/**
* 上传完成后服务器返回的数据
*/
private String responseStr = "";
public String getResponseStr() {
return responseStr;
}
public void setResponseStr(String responseStr) {
this.responseStr = responseStr;
}
public String getFilePath() {
return filePath;
}

@ -19,6 +19,7 @@ import com.arialyy.aria.core.common.AbsFtpInfoThread;
import com.arialyy.aria.core.common.OnFileInfoCallback;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTaskEntity;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import java.io.File;
import java.util.Properties;
@ -29,6 +30,7 @@ import org.apache.commons.net.ftp.FTPFile;
* 单任务远程服务器文件信息
*/
class FtpFileInfoThread extends AbsFtpInfoThread<UploadEntity, UploadTaskEntity> {
private static final String TAG = "FtpUploadFtpFileInfoThread";
static final int CODE_COMPLETE = 0xab1;
private boolean isComplete = false;
@ -56,12 +58,21 @@ class FtpFileInfoThread extends AbsFtpInfoThread<UploadEntity, UploadTaskEntity>
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);
}

@ -89,7 +89,8 @@ class HttpThreadTask extends AbsThreadTask<UploadEntity, UploadTaskEntity> {
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<UploadEntity, UploadTaskEntity> {
STATE.isRunning = false;
return;
}
mListener.onComplete();
STATE.isRunning = false;
}
@ -184,6 +184,7 @@ class HttpThreadTask extends AbsThreadTask<UploadEntity, UploadTaskEntity> {
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<UploadEntity, UploadTaskEntity> {
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();

@ -34,7 +34,7 @@ import java.util.Map;
class DBConfig {
static Map<String, Class> mapping = new HashMap<>();
static String DB_NAME;
static int VERSION = 22;
static int VERSION = 23;
static {
if (TextUtils.isEmpty(DB_NAME)) {

@ -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,会导致重复下载,进度错乱的问题;本版本已修复这个问题

@ -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)

@ -36,13 +36,9 @@ import java.io.File;
*/
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
//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<ActivityFtpDownloadBinding
case R.id.start:
Aria.download(this).loadFtp(URL, true).charSet("gbk")
//.login("sxf", "B34VdGsJ")
//.login("lao", "123456")
.login("lao", "123456")
.setDownloadPath("/mnt/sdcard/").start();
break;
case R.id.stop:

@ -23,11 +23,12 @@ import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.FileUtil;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityFtpUploadBinding;
import java.io.File;
/**
* Created by Aria.Lao on 2017/7/28.
@ -67,7 +68,7 @@ public class FtpUploadActivity extends BaseActivity<ActivityFtpUploadBinding> {
}
}
@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<ActivityFtpUploadBinding> {
}
@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) {

@ -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<ActivityUploadBinding> {
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<ActivityUploadBinding> {
}
@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<ActivityUploadBinding> {
}
@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<ActivityUploadBinding> {
@Upload.onTaskComplete public void taskComplete(UploadTask task) {
L.d(TAG, "上传完成");
L.d(TAG, "上传成功返回数据(如果有的话):" + task.getEntity().getResponseStr());
getBinding().setSpeed("");
getBinding().setProgress(100);
}

@ -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 下载框架'

Loading…
Cancel
Save