Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I get response header stream-media-id #59

Closed
lv2023100 opened this issue May 19, 2022 · 6 comments
Closed

How do I get response header stream-media-id #59

lv2023100 opened this issue May 19, 2022 · 6 comments
Labels

Comments

@lv2023100
Copy link

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

@Acconut
Copy link
Member

Acconut commented May 23, 2022

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!

@fujohnwang
Copy link

Same requirement +1

@Acconut
Copy link
Member

Acconut commented Dec 5, 2022

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

@fujohnwang
Copy link

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

@lv2023100
Copy link
Author

lv2023100 commented Dec 6, 2022

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

@Acconut Acconut mentioned this issue Jan 17, 2023
5 tasks
@Acconut
Copy link
Member

Acconut commented Jan 17, 2023

Thank you for your example, @lv2023100! We will implement a better way to access headers in the next major release: #78

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants