android实现图片上传功能(springMvc)
程序员文章站
2023-12-16 14:22:16
本文实例为大家分享了android图片上传的具体代码,供大家参考,具体内容如下
android端:
string filename = tvfilename.g...
本文实例为大家分享了android图片上传的具体代码,供大家参考,具体内容如下
android端:
string filename = tvfilename.gettext().tostring(); requestbody description = requestbody.create( okhttp3.multipartbody.form, filename); file fileimage = new file(savefilename); requestbody requestbody1 = requestbody.create(mediatype.parse("multipart/form-data"), fileimage); multipartbody.part body = multipartbody.part.createformdata("bannerimage", fileimage.getname(), requestbody1); restclient.api().addlive(description, body) .enqueue(new retrofit2.callback<responseinfo>() { @override public void onresponse(retrofit2.call<responseinfo> call, retrofit2.response<responseinfo> response) { "处理成功" } @override public void onfailure(retrofit2.call<responseinfo> call, throwable t) { "处理失败" } });
@multipart @post("add/live") call<responseinfo> addlive( @part("filename")requestbody filename,//其他字段 @part multipartbody.part bannerimage);//图片
服务器端:
@requestmapping(value = "/add/live", method = requestmethod.post) @responsebody public responseinfo addlive( @requestparam(value = "filename") string filename, @requestparam(value = "bannerimage") multipartfile bannerimage )throws exception { string logopath = "/logo/score/"; try { file file = new file(imagepath + logopath); fileutils.writebytearraytofile(file, bannerimage.getbytes()); } catch (exception e) { e.printstacktrace(); } return new responseinfo(t1tconstants.success, "成功"); }
参考:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。