How do I get response header stream-media-id
I'm using cloudflare stream tus, but its video id set "stream-media-id" in response header. How do I get response header stream-media-id?? https://developers.cloudflare.com/stream/uploading-videos/upload-video-file/#resumable-uploads-with-tus-for-large-files
This is not easily possible right now. One workaround is to subclass TusClient and overwrite the prepareConnection method to store a list of the HttpUrlConnections that tus-java-client makes: https://github.com/tus/tus-java-client/blob/master/src/main/java/io/tus/java/client/TusClient.java#L319
Once the upload is complete, you can inspect these connections and use HttpUrlConnection#getHeaderField to get the Stream-Media-ID header.
Hope that makes sense!
Same requirement +1
Thanks for letting us know, @fujohnwang. Please use the workaround from above for now.
Thanks for letting us know, @fujohnwang. Please use the workaround from above for now.
Thanks for the advice.
For the time being, I extract media id from returned URL(although it's not a recommended way as cloudflare docs says) 🤣
You can overidae prepareConnection method in TusClient.class. example:
public class TusClientDemo extends TusClient{
private HttpURLConnection connection;
@Override
public void prepareConnection(@NotNull HttpURLConnection connection) {
super.prepareConnection(connection);
this.connection = connection;
}
public HttpURLConnection getConnection() {
return connection;
}
public void setConnection(HttpURLConnection connection) {
this.connection = connection;
}
}
you can calling prepareConnection by TusClientDemo
TusClientDemo client = new TusClientDemo();
...
String streamId = client.getConnection().getHeaderField("stream-media-id");
Thank you for your example, @lv2023100! We will implement a better way to access headers in the next major release: https://github.com/tus/tus-java-client/issues/78