Android uses Retrofit2 RxJava file upload

Source: Internet
Author: User

Private Static voidUploadFinalContext Context,Final inttype, File logFile) {Map<string, requestbody> map =NewHashmap<>(); if(LogFile! =NULL&& logfile.length () > 0) {map.put (Parsemapkey ("File", Logfile.getname ()), Parserequestbody (LogFile)); } apifactory.getinstance (). Getapiservice (). Uploadlog (map). Compose (rxschedulers.<List<String>>combine ()). Subscribe (NewRxsubscriber1<list<string>>() {@Override Public voidOnError (apiexception e) {LOGUTIL.W ("Upload onfailure:"); } @Override Public voidOnNext (list<string>filepaths) {                        if(! Commonutil.isempty (filepaths))//Upload Successful{LOGUTIL.W ("Upload succ,filepath:" + filepaths.get (0)); Debughelp.printline ("Upload succ,filepath:" + filepaths.get (0));                        } File dir; if(Type = =upload_type_function) {dir=Logcollectorutility.getexternaldir (context, constants.function_dir_name); } Else{dir=Logcollectorutility.getexternaldir (context, constants.dir_name);                    } filetozip.recursiondeletefile (dir);    }                }); }     Public Staticrequestbody parserequestbody (file file) {returnRequestbody.create (Mediatype.parse ("Multipart/form-data"), file); }     Public Staticstring Parsemapkey (String key, String fileName) {returnKey + "\"; Filename=\ "" +FileName; }
/**     * Upload log     *     * @return * *    @Multipart    @POST ("v1/app/exception")    observable< Responsebean<list<string>>> Uploadlog (@PartMap map<string, requestbody> Map);

  

Android uses Retrofit2 RxJava file upload

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.