如何在Android Studio中上传图片?

时间:2019-05-05 11:11:31

标签: java android httpclient

我想将图像从图库上传到我在android studio中的服务器,我编写了代码来上传图像,但是无法正常工作。

这是我的代码,用于将图像上传到服务器。

在android studio中。



    public static String uploadImage(String filePath) throws IOException {

        String url = "http://www.cbs-kw.com/3733";
        String fileName = filePath;
        //file to be uploaded
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);
        StringBody comment = new StringBody("Filename: " + fileName);
        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("files", comment);
        httppost.setEntity(reqEntity);

        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
return  response.toString();
    }

和textview.set()不起作用,找不到上载图片的结果吗?

代码中的问题所在!

0 个答案:

没有答案