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

Unexpected status code (400) while uploading chunk #98

Open
krupasanghani023 opened this issue Oct 19, 2023 · 9 comments
Open

Unexpected status code (400) while uploading chunk #98

krupasanghani023 opened this issue Oct 19, 2023 · 9 comments
Labels

Comments

@krupasanghani023
Copy link

When i try to upload video on cloudflare unable to upload it and get io.tus.java.client.ProtocolException: unexpected status code (400) while uploading chunk error.

To Reproduce
Steps to reproduce the behavior:

  1. Select video and upload it
  2. If uploaded then please upload same video and check

Expected behavior
We can upload duplicate video all time no restriction is required

Setup details

  • Used tus-android-client version: [e.g. :0.1.11]
  • Used tus-java-client version: [e.g. :0.5.0]
@Acconut
Copy link
Member

Acconut commented Oct 19, 2023

You are likely missing a CloudFlare-specific settings, such as a header or URL parameter. I have no experience with their services, so I cannot help you much here. Maybe this discussion can lead you to a solution: tus/tus-java-client#66

@krupasanghani023
Copy link
Author

Have added header something like below one when i try to init tusclient. Is there any problem in it @Acconut?

try {
SharedPreferences pref = getSharedPreferences("tus", 0);
HashMap<String, String> hashMap = new HashMap<String, String>();

    hashMap.put("Content-Type", "application/json");
    hashMap.put("Authorization", "Bearer <token>");

    client = new TusClient();
    client.setHeaders(hashMap);
    client.setUploadCreationURL(new URL("https://api.cloudflare.com/client/v4/accounts/<account-id>/stream"));
    client.enableResuming(new TusPreferencesURLStore(pref));
} catch (Exception e) {
    showError(e);
}

@Acconut
Copy link
Member

Acconut commented Oct 19, 2023

Don't set Content-Type because tus-java-client has to change it. Also, I don't know if CloudFlare requires any other headers. Please look that up in their documentation.

@krupasanghani023
Copy link
Author

krupasanghani023 commented Oct 19, 2023

If we won't set Content-Type then also same error and Authentication header is require to cloudflare for authenticate it.

According to cloudflare doc it require below things:

curl -X POST \n
-d '{"url":"<video_url>","meta":{"name":"<video_name>"}}' \n
-H "Authorization: Bearer <api_token>" \n
https://api.cloudflare.com/client/v4/accounts/<account_id>/stream

This attached ss is of error which we get with tusclient:

Screenshot 2023-10-19 at 2 27 55 PM

@Acconut
Copy link
Member

Acconut commented Oct 19, 2023

I don't know CloudFlare's API but your request looks different than from what is described in their docs: https://developers.cloudflare.com/api/operations/stream-videos-initiate-video-uploads-using-tus

@krupasanghani023
Copy link
Author

Have updated same headers and check still same error is there:

io.tus.java.client.ProtocolException: unexpected status code (400) while creating upload
W/System.err: at io.tus.java.client.TusClient.createUpload(TusClient.java:211)
W/System.err: at io.tus.java.client.TusClient.resumeOrCreateUpload(TusClient.java:334)
W/System.err: at io.tus.android.example.MainActivity$UploadTask.doInBackground(MainActivity.java:177)
W/System.err: at io.tus.android.example.MainActivity$UploadTask.doInBackground(MainActivity.java:132)
W/System.err: at android.os.AsyncTask$3.call(AsyncTask.java:394)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:264)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)

@Acconut
Copy link
Member

Acconut commented Oct 19, 2023

The actual error message is probably available in the response body, but there is currently no easy way in tus-java-client to receive this body. That is something we have to improve in our API.

You could try the approach provided in tus/tus-java-client#89 to try and receive the response body from CloudFlare.

@krupasanghani023
Copy link
Author

Screenshot 2023-10-20 at 10 01 53 AM

Have added this override method and get error as Bad request

@Acconut
Copy link
Member

Acconut commented Oct 20, 2023

I had hoped for a more descriptive error message. My knowledge ends here and the reason for the error is probably something Cloudflare-specific. Maybe your environment doesn't support PATCH, which requires tus-java-client to use X-HTTP-Method-Override, which may not be supported by Cloudflare: tus/tus-java-client#66 (comment)

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

2 participants