Cloudflare Stream Beta Feedback

stream

#143

Hi, I’ve experienced the same problem like @ mszoke87 when I used java to upload a video to cloudflare programmatically. Do you have solution to this problem without modifying the TusClient library? We are considering cloudflare as a solution for our streaming platform, but we are heavily relying on java. That is why this could be a showstopper for us. Please advice.


#144

Hi @mszoke87. Thank you very much for the hints. Could you please give a little more explanation on your proposed fix (a code snippet will be perfect )? I’ve faced the same issue as you described in the post.


#145

It’s been awhile, but ultimately this is what I modified, based off of https://stackoverflow.com/questions/25163131/httpurlconnection-invalid-http-method-patch
In TusUploader.java I modified openConnection to reference a static method I added to the class which sets PATCH as an allowed method:

private void openConnection() throws IOException, ProtocolException {
        // Only open a connection, if we have none open.
        if(connection != null) {
            return;
        }

        bytesRemainingForRequest = requestPayloadSize;
        input.mark(requestPayloadSize);

        allowMethods("PATCH");

        connection = (HttpURLConnection) uploadURL.openConnection();
        client.prepareConnection(connection);
        connection.setRequestProperty("Upload-Offset", Long.toString(offset));
        connection.setRequestProperty("Content-Type", "application/offset+octet-stream");
        connection.setRequestProperty("Expect", "100-continue");
        try {
            connection.setRequestMethod("PATCH");
            // Check whether we are running on a buggy JRE
        } catch (java.net.ProtocolException pe) {
            connection.setRequestMethod("POST");
            connection.setRequestProperty("X-HTTP-Method-Override", "PATCH");
        }

        connection.setDoOutput(true);
        connection.setChunkedStreamingMode(0);
        try {
            output = connection.getOutputStream();
        } catch(java.net.ProtocolException pe) {
            // If we already have a response code available, our expectation using the "Expect: 100-
            // continue" header failed and we should handle this response.
            if(connection.getResponseCode() != -1) {
                finish();
            }

            throw pe;
        }
}

The allowMethods function:

private static void allowMethods(String... methods) {
        try {
            Field methodsField = HttpURLConnection.class.getDeclaredField("methods");

            Field modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt(methodsField, methodsField.getModifiers() & ~Modifier.FINAL);

            methodsField.setAccessible(true);

            String[] oldMethods = (String[]) methodsField.get(null);
            Set<String> methodsSet = new LinkedHashSet<>(Arrays.asList(oldMethods));
            methodsSet.addAll(Arrays.asList(methods));
            String[] newMethods = methodsSet.toArray(new String[0]);

            methodsField.set(null/*static field*/, newMethods);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
}

#146

Thank you on your prompt reply. That is the answer I was looking for. So you’ve uses reflection to extend the HttpUrlConnection class to accept the “PATCH” method. But what about TusUploader.java , you’ve change directly the class itself? If you are using the library as a Maven dependency you do not have access to the source code so you can not make changes on it. Do you actually fork the TusClient project change the source code and build a new jar that you than import it into your project?


#147

Yeah unfortunately i’ve had to check out the repo to do changes. It’s not necessarily a problem with the TusClient but the CloudFlare implementation. They need to support the Http-Method-Override header. My solution is not a long term solution.


#148

Who should I reach out to discuss pricing?


#149

I’d like to see manual video quality adjusting also, asap.


#150

There should be a way to implement Cloudflare Stream with Wordpress, using the existing Cloudflare for Wordpress plugin.

At the moment, I have to use an additional plugin to paste the Cloudflare stream code (so that TinyMCE wordpress editor doesn’t remove the tag automatically).

Furthermore, requesting manual/pre-set video quality adjusting (my videos are high-definitely PC tutorials, so a low-def video makes no sense).

Finally, integrating Signed URLs with the Wordpress plugin would be fantastic. I have no idea how to do this with code (to prevent pirating of the videos).

Once this has been implemented, this will potentially replaces the secure Flash RMTP permanently.

Thanks again.