Skip to content

Commit 30d36c2

Browse files
committed
Update README.md
1 parent 69dd162 commit 30d36c2

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

docs/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,28 @@ class ResumableIO {
133133
final PutExtra extra = new PutExtra();
134134
final String key = "key";
135135
final String filepath = "xx/xx/xx";
136+
// 准备上传
137+
db.execute("INSERT INTO `table_resumable_table` (`key`, `filepath`) VALUES ('" + key + "', '" + filepath + "')");
136138
ResumableIO.put(key, InputStreamAt.fromFile(new File(filepath)), extra, new JSONObjectRet() {
137139
int process;
140+
private void persist() {
141+
// 持久化
142+
db.execute("UPDATE `table_resumable_table` SET extra='" + extra.toJSON() + "', process=" + process + " WHERE `key`='" + key + "' and `filepath`='" + filepath + "'");
143+
}
144+
public void onSuccess(JSONObject obj) {
145+
// 上传成功,删除记录
146+
db.execute("DELETE FROM `table_resumable_table` WHERE `key`='" + key + "' and `filepath`='" + filepath + "'");
147+
}
138148
public void onProcess(int current, int total) {
139-
process = current/total;
149+
process = current*100/total;
150+
// 每5%持久化一次
151+
if (process % 5 == 0) {
152+
persist();
153+
}
140154
}
141-
// ...省略成功分支处理代码
142155
public void onFailure(Exception ex) {
143156
// 忽略处理exception,
144-
db.execute("INSERT INTO `table_resumable_table` (`key`, `filepath`, `extraJson`, `process`) VALUES ('" + key + "', '" + filepath + "', '" + extra.toJSON() + "', " + process + ")");
157+
persist();
145158
}
146159
})
147160
```

0 commit comments

Comments
 (0)