在服务器上上传后如何删除图像/文档?

时间:2019-02-06 12:26:34

标签: android server gallery

在服务器上上传后,我想删除客户图像(从我保存在外部存储器中的相机中拍摄的图像)。 而且我正在使用FilePicker获取客户文档,它也具有相机选项。使用FilePicker获取文档后,在图库中可以看到图像,我不想。

如果我想对客户数据进行一些修改,这些图像在我的应用程序中仍然可用吗? 。

有人可以帮助我吗?

我应该在哪里编写删除图片或文档的代码

这里是用于从相机拍摄图像的代码。

  if (view == takePicBtn) {
        SelectImage();
    }

private void SelectImage() {

    final CharSequence[] items = {"Camera", "Cancel"};

    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle("Add Image");

    builder.setItems(items, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            if (items[i].equals("Camera")) {

                Intent intent = new 
                   Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if                    
               (intent.resolveActivity(getActivity().getPackageManager()) 
                  != null) {
                    try {
                        photoFile = createImageFile();
                    } catch (IOException ioExp) {

                    }
                    if (photoFile != null) {
                        photoURI = 
            FileProvider.getUriForFile(getActivity(), "com.shery.safco", 
               photoFile);
                        intent.putExtra(MediaStore.EXTRA_OUTPUT, 
                         photoURI);
                        startActivityForResult(intent, REQUEST_CAMERA);
                    }

                }
            } else if (items[i].equals("Cancel")) {
                dialogInterface.dismiss();
            }

        }
    });
    builder.show();

}

 private File createImageFile() throws IOException {

    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new 
     Date());
    String imageFileName = "image_" + timeStamp + "_";
    File storageDir = 
        activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".aaa",         /* suffix */
            storageDir      /* directory */
    );
    filePaths = image.getAbsolutePath();

    return image;
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent 
     data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {

        if (requestCode == REQUEST_CAMERA) {

            Bitmap bitmap = CommonMethod.compressImage(photoFile, 
        getContext());
            mCustomerImage = CommonMethod.bitmapToByteArray(bitmap);
            imageTemplateStr = Base64.encodeToString(mCustomerImage, 
 Base64.DEFAULT);
            imageCustomer.setImageBitmap(bitmap);
        }

    }

 }

获取文档的代码。

else if (view == pickPhotoBtn) {

        FilePickerBuilder.getInstance().setMaxCount(10)
                .setActivityTheme(R.style.AppTheme3)
                .pickPhoto(getActivity());

 }
获取文档后的

OnActivityResult()方法。

@Override
public void onActivityResult(int requestCode, int resultCode, Intent 
    data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {

        case FilePickerConst.REQUEST_CODE_PHOTO:

            if (resultCode == Activity.RESULT_OK && data != null) {
                Log.e(TAG, "onActivityResult: ");
                for (String path : 
       data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_PHOTOS)) 
 {
                    String fileName = 
     CommonMethod.getFileNameFromPath(path);

                    Log.e("DocPath : ", path);

                    if (!documentNameList.contains(fileName) && 
       !selectPhotosPath.contains(path) && selectPhotosPath.size() < 10) 
             {
                        selectPhotosPath.add(path);
                        File file = new File(path);
                        Log.e(TAG, "Image Name: " + fileName);
                        documentNameList.add(fileName);
                        documentIdList.add(0);

          selectPhotosBitmap.add(CommonMethod.compressImage(file, 
         getContext()));
                    }
                }

                adapter.addItems(selectPhotosBitmap);
                adapter.notifyDataSetChanged();
                Log.e(TAG, "Number Of Files: " + 
             selectPhotosPath.size());
            }

    }
 }

用于上传文档的代码。

 public void uploadDocument(final ArrayList<Document> documents) {

    if (documents.size() == 0) {
        if (progressDialog.isShowing())
            progressDialog.dismiss();
        imageCount = 1;
        uploadGroupData();
        return;
    }
    CommonMethod.writeToFile(new Gson().toJson(documents.get(0)));
  //        Log.d(TAG, "uploadDocument: For Debuging");
    Document document = documents.get(0);

    if (oldNic != null && 
   !oldNic.equalsIgnoreCase(document.getNicNumber())) {
        oldNic = document.getNicNumber();
        documentCount = 1;
    }

    RequestParams params = new RequestParams();
    params.put("document_count", documentCount);
    params.put("document_data", new Gson().toJson(document));

    /*params.put(Document.KEY_IMAGE_NAME, document.getImageName());
    params.put(Document.KEY_IMAGE, document.getImage());
    params.put(Document.KEY_LOAN_ID, document.getLoanId());
    params.put(Document.KEY_DOC_ADDED_DATETIME, 
    document.getDocumentAddedDataTime());*/
    //TODO Test URL For Debugging 2
    PhpConnectivity.getClient().post(CommonConst.DOCUMENT_TEST_URL, 
    params, new AsyncHttpResponseHandler() {
        @Override
        public void onStart() {
            super.onStart();

            if (progressDialog.isShowing()) {
                progressDialog.setMessage("Uploading Document " + 
     imageCount + " of " + imgTotalCount);
            } else {
                progressDialog.setTitle("Documents Sync Up");
                progressDialog.setMessage("Uploading Document " + 
     imageCount + " of " + imgTotalCount);
                progressDialog.setCancelable(false);
                progressDialog.show();
            }
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] 
      responseBody) {
            String response = new String(responseBody);
            if (response.equalsIgnoreCase(RESPONSE_SUCCESS)) {
                Log.e(TAG, "Document Sync Up Response: " + response);
                imageCount++;
                documentCount++;
                documents.remove(0);
                uploadDocument(documents);
            } else {
                Log.e(TAG, "Sync Up Failure: " + response);
                progressDialog.dismiss();
                CommonMethod.alert(SyncUpActivity.this
                        , "Document Sync Up Failure:", "Response: " + 
        response);

            }


        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] 
        responseBody, Throwable error) {
            if (responseBody == null) {
                CommonMethod.alert(SyncUpActivity.this
                        , "Connectivity Error:", "Try Again!");
                progressDialog.dismiss();
                return;
            }
            String response = new String(responseBody);
            Log.e(TAG, "onFailure: " + response);
            CommonMethod.alert(SyncUpActivity.this
                    , "Document Sync Up Failure:", "Response: " + 
   response);
            progressDialog.dismiss();
        }


    });

}

用于上传组数据的代码(与组数据一起发送的客户图像)

public void uploadGroupData() {
//        Log.e(TAG, "group_data: "+ new Gson().toJson(groupSyncUpData));
    CommonMethod.writeToFile(new Gson().toJson(groupSyncUpData));

    RequestParams params = new RequestParams();

    int id = dbHandler.getEmployeeID(preferences.getFirstname());
    params.put("EmployeeId" , new Gson().toJson(id));
    params.put("group_data", new Gson().toJson(groupSyncUpData));

    Log.e("ParamsJason : ", ""+params);

  //TODO Test URL For Debugging 1

    PhpConnectivity.getClient().post(CommonConst.GROUP_TEST_URL, params, 
    new AsyncHttpResponseHandler() {
        @Override
        public void onStart() {
            super.onStart();
            progressDialog.setTitle("Group Sync Up");
            progressDialog.setMessage("Group  Data Uploading...");
            progressDialog.setCancelable(false);
            progressDialog.show();
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] 
        responseBody) {
            String response = new String(responseBody);
            if (response.trim().equalsIgnoreCase(RESPONSE_SUCCESS)) {
                progressDialog.dismiss();
                CommonMethod.alert(SyncUpActivity.this
                        , "Group Sync Up:", "Success")            

       dbHandler.updateGroupSync(groupSyncUpData.getGroup().getGroupId(), 
        1);

      recAdapter.getItemList().remove(groupSyncUpData.getGroup());
                recAdapter.notifyDataSetChanged();
                groupSyncUpData = null;
            } else {
                Log.e(TAG, "onFailure: " + response);
                progressDialog.dismiss();
                CommonMethod.alert(SyncUpActivity.this
                        , "Group Sync Up Failure:", "Response: " + 
       response);
            }

        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] 
        responseBody, Throwable error) {
            if (responseBody == null) {
                CommonMethod.alert(SyncUpActivity.this
                        , "Connectivity Error:", "Try Again!");
                progressDialog.dismiss();
                return;
            }
            String response = new String(responseBody);
            Log.e(TAG, "onFailure: " + response);
            progressDialog.dismiss();
            CommonMethod.alert(SyncUpActivity.this
                    , "Group Sync Up Failure:", "Response: " + response);

        }
    });
}

0 个答案:

没有答案