1

I am working on job portal app in which i want to upload the resume in all formats like .doc,.docx and .pdf. Currrently only one file format is supported at a time. Below is what i have done:

Intent intent = new Intent();
            intent.setType("application/pdf,application/msword");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            startActivityForResult(intent, REQUEST_CODE_DOC);

Please help me how to do this.Thanks in advance

Monali
  • 270
  • 1
  • 5
  • 16
  • Maybe you should not use volley , volley is only for short and fast request, you should try httpclient or retrofit . – cowboi-peng May 24 '17 at 07:49

2 Answers2

0

Try this link. Basically what you have to do is read the file convert to bytes and then override getBody method in the volley request.

Bijesh
  • 317
  • 3
  • 11
0
  public void upload(){
                    Intent intent = new Intent();
                    intent.setType("application/pdf,application/msword");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    intent.addCategory(Intent.CATEGORY_BROWSABLE);
                    startActivityForResult(intent, REQUEST_CODE_DOC);

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) 
                          {
                                File file=new File(getPath(Payment_upload.this,uri));
                                String path=getPath(context,uri);
                                upload_file=getStringFile(file);
                           }


                VolleyMultipartRequest multipartRequest = new VolleyMultipartRequest(Request.Method.POST, u, new Response.Listener<NetworkResponse>() {
                    @Override
                    public void onResponse(NetworkResponse response) {
                        String resultResponse = new String(response.data);

                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        NetworkResponse networkResponse = error.networkResponse;
                        String errorMessage = "Unknown error";
                        if (networkResponse == null) {
                            if (error.getClass().equals(TimeoutError.class)) {
                                errorMessage = "Request timeout";
                            } else if (error.getClass().equals(NoConnectionError.class)) {
                                errorMessage = "Failed to connect server";
                            }
                        } else {
                            String result = new String(networkResponse.data);
                            System.out.println(result);
                        }
                        Log.i("Error", errorMessage);
                        error.printStackTrace();
                    }
                }) {


                    @Override
                    protected Map<String, String> getParams() throws AuthFailureError {
                        Map<String, String> parameters = new HashMap<String, String>();
                        parameters.put("key", value);

                        return parameters;
                    }
                };

                VolleySingleton.getInstance(getBaseContext()).addToRequestQueue(multipartRequest);

                   }

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static String getPath(final Context context, final Uri uri) {

    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }


        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(
                    Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] {
                    split[1]
            };

            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {
        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}



    @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
            super.onActivityResult(requestCode, resultCode, data);

            if (requestCode == REQUEST_CODE_DOC && resultCode == RESULT_OK && data != null && data.getData() != null)
            {
               Uri uri=data.getData();
            }

        }
AmarDurai
  • 91
  • 1
  • 8