|
14 | 14 | import io.reactivex.disposables.CompositeDisposable;
|
15 | 15 | import java.io.File;
|
16 | 16 | import java.io.IOException;
|
| 17 | +import java.io.UnsupportedEncodingException; |
| 18 | +import java.net.URLEncoder; |
17 | 19 | import java.util.Date;
|
18 | 20 | import java.util.HashMap;
|
19 | 21 | import java.util.List;
|
|
34 | 36 | @Singleton
|
35 | 37 | public class UploadClient {
|
36 | 38 |
|
37 |
| - private final int CHUNK_SIZE = 256 * 1024; // 256 KB |
| 39 | + private final int CHUNK_SIZE = 512 * 1024; // 512 KB |
38 | 40 |
|
39 | 41 | //This is maximum duration for which a stash is persisted on MediaWiki
|
40 | 42 | // https://www.mediawiki.org/wiki/Manual:$wgUploadStashMaxAge
|
@@ -134,18 +136,23 @@ Observable<StashUploadResult> uploadFileToStash(
|
134 | 136 | new ChunkInfo(uploadResult, index.get(), totalChunks));
|
135 | 137 | notificationUpdater.onChunkUploaded(contribution, chunkInfo.get());
|
136 | 138 | }, throwable -> {
|
| 139 | + Timber.e(throwable, "Received error in chunk upload"); |
137 | 140 | failures.set(true);
|
138 | 141 | }));
|
139 | 142 | }));
|
140 | 143 |
|
141 | 144 | if (pauseUploads.get(contribution.getPageId())) {
|
| 145 | + Timber.d("Upload stash paused %s", contribution.getPageId()); |
142 | 146 | return Observable.just(new StashUploadResult(StashUploadState.PAUSED, null));
|
143 | 147 | } else if (failures.get()) {
|
| 148 | + Timber.d("Upload stash contains failures %s", contribution.getPageId()); |
144 | 149 | return Observable.just(new StashUploadResult(StashUploadState.FAILED, null));
|
145 | 150 | } else if (chunkInfo.get() != null) {
|
| 151 | + Timber.d("Upload stash success %s", contribution.getPageId()); |
146 | 152 | return Observable.just(new StashUploadResult(StashUploadState.SUCCESS,
|
147 | 153 | chunkInfo.get().getUploadResult().getFilekey()));
|
148 | 154 | } else {
|
| 155 | + Timber.d("Upload stash failed %s", contribution.getPageId()); |
149 | 156 | return Observable.just(new StashUploadResult(StashUploadState.FAILED, null));
|
150 | 157 | }
|
151 | 158 | }
|
@@ -176,9 +183,11 @@ Observable<UploadResult> uploadChunkToStash(final String filename,
|
176 | 183 | final long offset,
|
177 | 184 | final String fileKey,
|
178 | 185 | final CountingRequestBody countingRequestBody) {
|
179 |
| - final MultipartBody.Part filePart = MultipartBody.Part |
180 |
| - .createFormData("chunk", filename, countingRequestBody); |
| 186 | + final MultipartBody.Part filePart; |
181 | 187 | try {
|
| 188 | + filePart = MultipartBody.Part |
| 189 | + .createFormData("chunk", URLEncoder.encode(filename, "utf-8"), countingRequestBody); |
| 190 | + |
182 | 191 | return uploadInterface.uploadFileToStash(toRequestBody(filename),
|
183 | 192 | toRequestBody(String.valueOf(fileSize)),
|
184 | 193 | toRequestBody(String.valueOf(offset)),
|
@@ -227,6 +236,7 @@ Observable<UploadResult> uploadFileFromStash(final Context context,
|
227 | 236 | UploadResponse uploadResult = gson.fromJson(uploadResponse, UploadResponse.class);
|
228 | 237 | if (uploadResult.getUpload() == null) {
|
229 | 238 | final MwException exception = gson.fromJson(uploadResponse, MwException.class);
|
| 239 | + Timber.e(exception, "Error in uploading file from stash"); |
230 | 240 | throw new RuntimeException(exception.getErrorCode());
|
231 | 241 | }
|
232 | 242 | return uploadResult.getUpload();
|
|
0 commit comments