411/412 error while using tus-java-client
还没有人认领这个 Issue。
评估
调研方向
Start with TusClient.createUpload at the stack trace location and compare the creation request headers with the tus protocol and the working tus-js request. Check whether the headers added to the map after client.setHeaders are included in the request, and inspect the tusdotnet response for the 412 cause. Done means identifying the cause and confirming upload creation succeeds with the Java client.
由索引模型根据 Issue 内容生成。
描述
Question
We have a tusdotnet server and tus-js which is working perfectly fine. We are planning to add a tus-java-client as well for our product and have developed a simple java application to test the tus-java-client but, I'm consistently receiving 411 error. after looking at this article and followed the instructions and now I'm receiving 412 error. I'm not sure what headers I'm missing because I'm using the same headers from tus-js. Any help is appreciated
Thanks
Setup details
Please provide following details, if applicable to your situation:
- Runtime environment: [OpenJDK 23.0.1]
- Used tus-java-client version: [0.5.0]
- Used tus server software: [tusdotnet]
package com.example;
import io.tus.java.client.TusClient;
import io.tus.java.client.TusUpload;
import io.tus.java.client.TusUploader;
import org.apache.log4j.Logger;
import java.io.File;
import java.net.URL;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
public class App {
static final Logger logger = Logger.getLogger(App.class);
public static void main(String[] args) {
try {
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
// File path and server URL
String filePath = "C:\\myfile\\path.jpg";
URL uploadURL = new URL("MyURL");
// Initialize the TUS client
TusClient client = new TusClient();
client.setUploadCreationURL(uploadURL);
// Prepare the file
File file = new File(filePath);
if (!file.exists()) {
logger.error("File not found: " + filePath);
return;
}
long fileSize = file.length();
// Set headers
Map<String, String> headers = new HashMap<>();
headers.put("Tus-Resumable", "1.0.0");
headers.put("Upload-Length", String.valueOf(fileSize));
headers.put("X-Token", "<Your-Actual-Token>");
logger.debug("Headers set: " + headers);
client.setHeaders(headers);
// Create the upload
TusUpload upload = new TusUpload(file);
upload.setSize(fileSize);
// Set metadata
Map<String, String> metadata = new HashMap<>();
metadata.put("filename", file.getName());
metadata.put("filetype", "image/jpeg");
// Set additional metadata as observed
//Metadata added here
// Encode metadata
StringBuilder encodedMetadata = new StringBuilder();
for (Map.Entry<String, String> entry : metadata.entrySet()) {
if (encodedMetadata.length() > 0) {
encodedMetadata.append(",");
}
String encodedValue = Base64.getEncoder().encodeToString(entry.getValue().getBytes("UTF-8"));
encodedMetadata.append(entry.getKey()).append(" ").append(encodedValue);
}
headers.put("Upload-Metadata", encodedMetadata.toString());
// Create and start the upload process
TusUploader uploader = client.createUpload(upload);
uploader.setChunkSize(1024 * 1024); // 1MB chunk size
logger.info("Starting upload process.");
while (uploader.uploadChunk() > -1) {
long uploadedBytes = uploader.getOffset();
logger.info(String.format("Uploaded %d of %d bytes", uploadedBytes, fileSize));
}
uploader.finish();
logger.info("Upload completed successfully!");
} catch (Exception e) {
logger.error("Failed to complete upload", e);
}
}
}
This is my Error
ERROR App:101 - Failed to complete upload
io.tus.java.client.ProtocolException: unexpected status code (412) while creating upload
at io.tus.java.client.TusClient.createUpload(TusClient.java:211)
at com.example.App.main(App.java:88)
at org.codehaus.mojo.exec.ExecJavaMojo.doMain(ExecJavaMojo.java:375)
at org.codehaus.mojo.exec.ExecJavaMojo.doExec(ExecJavaMojo.java:364)
at org.codehaus.mojo.exec.ExecJavaMojo.lambda$execute$0(ExecJavaMojo.java:286)
at java.base/java.lang.Thread.run(Thread.java:1575)
- 主要语言
- Java
- 星标
- 246
- 派生
- 90
- 平均合并
- 13 小时 2 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tus/tus-java-client 的其他 Issue
-
question
难度 3/5 1-2 天 新手友好度 35/100
tus/tus-java-client#144 · 1 条评论 ·
-
tus 2.0 support未关闭enhancement
难度 5/5 一周以上 新手友好度 20/100
tus/tus-java-client#114 · 1 条评论 ·
-
question
难度 4/5 3-5 天 新手友好度 25/100
tus/tus-java-client#113 · 1 条评论 ·
-
enhancement
难度 4/5 3-5 天 新手友好度 39/100
tus/tus-java-client#98 ·
-
难度 5/5 一周以上 新手友好度 15/100
tus/tus-java-client#78 · 8 条评论 · 1 个 reaction ·
查看 tus/tus-java-client 的全部 Issue
相似的 Issue
-
Type: Bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
MCP add-on: JSON responses with non-ASCII characters are truncated (wrong Content-Length)可能已有人在做 @dhanushbs10 今天认领。 未关闭add-on bug in:mcp
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Map.Coordinate does not implement proper equals可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭vaadin-map
难度 2/5 1-3 小时 新手友好度 70/100
vaadin/flow-components#10586 ·
维护者通常 1 天内回复
-
WeReadInstaller writes the launcher database on the main thread at handover (Activity pause timeout)未关闭bug good first issue
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 63/100
wpilibsuite/SystemcoreTesting#446 ·
维护者通常 1 天内回复