web services - Upload Video Android server error 404 -
i'm trying upload video via webservice created me in java. sends video server returns "400 error, parameters wrong"
did guys can me?
private class sendvideotask extends asynctask<void, void, string> { @override protected string doinbackground(void... params) { try { final string url = server_url + "/rest/cloud/uploadfilepost"; form form = new form(); form.add("test_id", test_id); form.add("report_id", report_id); string encoded_file = cc.encodefiletobase64binary(mediafile); form.add("encoded_file", encoded_file); string resp = ""; closeablehttpclient httpclient = httpclients.createsystem(); httppost httppost = new httppost(url); list<namevaluepair> urlparameters = new arraylist<namevaluepair>(); urlparameters.add(new basicnamevaluepair("test_id", test_id)); urlparameters.add(new basicnamevaluepair("report_id", string .valueof(report_id))); urlparameters.add(new basicnamevaluepair("encoded_file", encoded_file)); httppost.setentity(new urlencodedformentity(urlparameters)); closeablehttpresponse response = httpclient.execute(httppost); try { httpentity entity = response.getentity(); if (entity != null) { inputstream instream = entity.getcontent(); try { resp = entityutils.tostring(entity); } { instream.close(); } } } { response.close(); httpclient.getconnectionmanager().shutdown(); } return resp; } catch (exception e) { log.e("videoasynctask (background)", e.getmessage(), e); // toast.maketext(getapplicationcontext(), // "error: " + e.getmessage(), toast.length_long).show(); } return null; } }
the webservice java
@produces(mediatype.text_plain) @requestmapping(value = "/rest/cloud/uploadfilepost", method = requestmethod.post) @responsestatus(httpstatus.ok) public responseentity<string> uploadpostvideo( @requestparam(value = "test_id") string test_id, @requestparam(value = "report_id") string report_id, @requestparam(value = "encoded_file") string encoded_file) { string output = ""; httpheaders responseheaders = new httpheaders(); logger log = logger.getlogger("com.vodafone.webmobiletestingsuite"); byte[] bytes = base64.decodebase64(encoded_file); string file_name = "video" + report_id + ".mp4"; try { file file = new file(file_name); fileoutputstream fos = new fileoutputstream(file); fos.write(bytes); fos.close(); log.info("starting post cloud"); cloudbo = new cloudbo(); output = cloudbo.uploadfile(report_id, file); log.info("file path: " + file.getabsolutepath()); boolean r = file.delete(); log.info("delete: " + r); log.info("finish post cloud"); usabilityreport ur = bousabilityreports.findbyid( integer.parseint(report_id), usabilityreport.class); log.info("start attachment"); log.info("report id:" + ur.getexecutionreportid()); cameraattachment ca = new cameraattachment(); ca.setpublicurl(output.split(";")[1]); log.info("public url:" + output.split(";")[1]); ca.setusability_report(ur); log.info("finish attachment"); bocameraattachments.create(ca); } catch (filenotfoundexception e) { output = "filenotfound_exception"; } catch (ioexception e) { output = "io_exception"; } catch (dbxexception e) { output = "dbx: " + e.tostring(); } responseheaders.set("access-control-allow-origin", "*"); responseheaders.set("access-control-allow-methods", "post, get, put, update, options"); responseheaders.set("access-control-allow-headers", "content-type, accept, x-requested-with"); return new responseentity<string>(output, responseheaders, httpstatus.ok); }
the problem server end. try using multipartfile class in spring. here simple tutorial can http://www.journaldev.com/2573/spring-mvc-file-upload-example-tutorial-single-and-multiple-files
Comments
Post a Comment