tus-java-client icon indicating copy to clipboard operation
tus-java-client copied to clipboard

How do I get response header stream-media-id

Open lv2023100 opened this issue 3 years ago • 1 comments

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

lv2023100 avatar May 19 '22 04:05 lv2023100

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!

Acconut avatar May 23 '22 12:05 Acconut

Same requirement +1

fujohnwang avatar Dec 05 '22 10:12 fujohnwang

Thanks for letting us know, @fujohnwang. Please use the workaround from above for now.

Acconut avatar Dec 05 '22 13:12 Acconut

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) 🤣

fujohnwang avatar Dec 06 '22 03:12 fujohnwang

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");

lv2023100 avatar Dec 06 '22 05:12 lv2023100

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

Acconut avatar Jan 17 '23 11:01 Acconut