请考虑以下代码。我们正在使用 TUSClient 分块上传大文件。
public void uploadFile(UploadFileResponse uploadFileResponse, File file) {
try {
if (System.getProperty("sun.net.http.allowRestrictedHeaders") == null) {
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
}
byte[] bytes = Files.readAllBytes(file.toPath());
Map headers = new HashMap();
headers.put("token", getToken());
headers.put("Content-Length", Integer.toString(bytes.length));
final TusUpload upload = new TusUpload(file);
TusClient client = new TusClient();
client.setUploadCreationURL(new URL(uploadFileResponse.getUploadUrl()));
client.setHeaders(headers);
client.enableResuming(new TusURLMemoryStore());
Integer chunkSize = 1024 * 1024 * 1;
Map metadata = new HashMap();
metadata.put("name", file.getName());
metadata.put("chunkSize", String.format("%d", chunkSize));
metadata.put("contentType", "text/xml");
upload.setMetadata(metadata);
TusExecutor executor = new TusExecutor() {
@Override
protected void makeAttempt() throws IOException, ProtocolException {
TusUploader uploader = client.resumeOrCreateUpload(upload);
uploader.setChunkSize(chunkSize);
int result = 0;
do {
result = uploader.uploadChunk();
} while (result > -1);
uploader.finish();
}
};
executor.makeAttempts();
}catch (Exception e){
throw new customException(e);
}
}
现在上面的代码在没有代理的环境中工作。现在如果需要代理支持,如何在 TUSClient 中添加代理支持。