Tus upload Android/Java error 400 -
i'm trying upload image tus server on android io.tus.java.client:tus-java-client:0.3.1. decided perform upload in intentservice, code (as suggested on github):
private static final string tus_url = "http://master.tus.io/files/"; private string uploadimage(resultreceiver receiver, bundle bundle, string imagepath) throws ioexception, protocolexception, urisyntaxexception { tusclient client = new tusclient(); client.setuploadcreationurl(new url(tus_url)); sharedpreferences pref = getsharedpreferences("tus", 0); client.enableresuming(new tuspreferencesurlstore(pref)); file file = new file(new uri(imagepath)); final tusupload upload = new tusupload(file); //upload.setsize(file.length()); //map<string, string> metadata = new hashmap<>(); //metadata.put("filename", file.getname()); //upload.setmetadata(metadata); tusexecutor executor = new tusexecutor() { @override protected void makeattempt() throws protocolexception, ioexception { // first try resume upload. if that's not possible create new // upload , tusuploader in return. class responsible opening // connection remote server , doing uploading. tusuploader uploader = client.resumeorcreateupload(upload); // upload file in chunks of 1kb sizes. uploader.setchunksize(1024); // upload file long data available. once // file has been uploaded method return -1 { // calculate progress using total size of uploading file , // current offset. long totalbytes = upload.getsize(); long bytesuploaded = uploader.getoffset(); long progress = (long) bytesuploaded / totalbytes * 100; bundle.putint("progress",progress.intvalue()); receiver.send(status_progress,bundle); //system.out.printf("upload @ %06.2f%%.\n", progress); } while(uploader.uploadchunk() > -1); // allow http connection closed , cleaned uploader.finish(); system.out.println("upload finished."); system.out.format("upload available at: %s", uploader.getuploadurl().tostring()); } }; executor.makeattempts(); return java.util.uuid.randomuuid().tostring(); }
unfortunately, keeps throwing protocolexception code 400. file url ok, i'm sure because there no ioexception thrown. after sending few chunks, stops , throws protocolexception. have tried compile official android sample, , able send half of file, same - protocolexception eror 400.
do have ideas? i'm stuck , don't know other tus protocol implementation java try (is there any?). thanks.
Comments
Post a Comment