tus-android-client
tus-android-client copied to clipboard
Unexpected status code (400) while uploading chunk
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:
- Select video and upload it
- 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]
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: https://github.com/tus/tus-java-client/issues/66
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);
}
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.
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:
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
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)
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 https://github.com/tus/tus-java-client/issues/89 to try and receive the response body from CloudFlare.
Have added this override method and get error as Bad request
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: https://github.com/tus/tus-java-client/issues/66#issuecomment-1280052624