Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何上传存储在内存文件中的所有图像_Android - Fatal编程技术网

Android 如何上传存储在内存文件中的所有图像

Android 如何上传存储在内存文件中的所有图像,android,Android,我需要发送一个文件中存储的所有图像。现在,我通过指定一个图像的名称,在点击按钮时发送一个图像。但如何发送按钮点击保存在某个文件夹中的所有图像 public class UploadImagesToServer { public static void postImage(String ImageLink){ RequestParams params = new RequestParams(); try { params.put("file", new Fil

我需要发送一个文件中存储的所有图像。现在,我通过指定一个图像的名称,在点击按钮时发送一个图像。但如何发送按钮点击保存在某个文件夹中的所有图像

public class UploadImagesToServer {


public static void postImage(String ImageLink){

    RequestParams params = new RequestParams();
    try {
        params.put("file", new File(ImageLink));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    AsyncHttpClient mNewCaller = new AsyncHttpClient();


    mNewCaller.get(Constants.MediaUpload, params, new JsonHttpResponseHandler() {
        @Override
        public void onStart() {
            super.onStart();
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            super.onSuccess(statusCode, headers, response);
            Log.e("response page", response.toString());


        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, String responseString) {
            super.onSuccess(statusCode, headers, responseString);
            Log.e("frag", responseString + " " + statusCode);

        }
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray responseString) {
            super.onSuccess(statusCode, headers, responseString);
            Log.e("frag", responseString + " " + statusCode);

        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            super.onFailure(statusCode, headers, throwable, errorResponse);
            Log.e("fail 3", statusCode + "" + errorResponse);
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            super.onFailure(statusCode, headers, responseString, throwable);
            Log.e("fail 3", statusCode + "" + responseString);
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
            super.onFailure(statusCode, headers, throwable, errorResponse);
            Log.e("fail 3", statusCode + "" + errorResponse);
        }
    });

}
}

以上代码用于发送图像

    continueBtn.setOnClickListener(new View.OnClickListener() {
        @Override

        public void onClick(View v) {
            String filePath = Environment.getExternalStorageDirectory()
                    .getAbsolutePath() + File.separator + "/Omoto Images/background image.jpg";
            UploadImagesToServer.postImage(filePath);
        }
    });

这是用于调用PostImageMethod

上传多个图像的最佳过程。 您的图像上传代码已经实现,您只需更改流即可

您可以将图像路径存储在列表(或类似内容)中,并保存 列表(可以是共享首选项或sqlite)。 上传完图片后,将其从列表中删除并继续下一张,以此类推,直到列表为空为止

上传时,如果互联网连接中断,不会影响您, 您将始终保存仍要上载的图像列表

对于“获取所有图像”路径: 您需要扫描目录和存储图像路径,并在上载之前检查路径文件是否存在,因为有时图像可能会被删除或移动