0

I have to send 12 parameters including one pdf file to generate a registered pdf.

problem is that while debugging i get /data/filename.pdf but server not reading file path.

and in phone the path location is showing like /sdcard/filename.pdf

Phone info: marshmallow (API 23+)

what changes i need to make to read its file path?

i tried using

1) Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)

2)

  File readpdfFile = new File(Environment.getDataDirectory() + File.separator +
                            "/NewPDF_.pdf");

                        propOne.setName("arg0");
                        propOne.setValue(readpdfFile);
                        request.addProperty(propOne);
// 11 other parameters similar as above
//soap method
 SoapSerializationEnvelope envelope2 = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                new MarshalBase64().register(envelope2);
                envelope2.setOutputSoapObject(request);

                envelope2.implicitTypes = false;
                androidTransport = new HttpTransportSE(WSDL_URL);
                androidTransport.debug = true;
                androidTransport.call(SOAP_ACTION, envelope2);

                SoapObject response2 = (SoapObject) envelope2.bodyIn;
                String requestDump = androidTransport.requestDump;
                String responseDump = androidTransport.responseDump;

                Log.i("", "Request: " + requestDump);
                Log.i("", "Response: " + responseDump);

                outRes = response2.toString();

                pdfResult = outRes;
                Log.d("pdfResult  ", pdfResult);

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            return pdfResult;
        }
benjamin
  • 1
  • 4
  • Use Environment.getExternalStorageDirectory(). – greenapps Oct 25 '16 at 08:04
  • i used it.. but still it cant read it by server and response is null. plus updated the code for more simplification – benjamin Oct 25 '16 at 09:12
  • Well have you checked if the file exist before sending its path to server? `File readpdfFile`. Use `if (!readpdfFile.exists()){Toast to tell that the user; return;}`. – greenapps Oct 25 '16 at 09:26
  • Paths on your Android device cannot be read by servers on the internet. So it is pretty unclear what you are trying to accomplish. Should the path be read by the ksoap client instead to send its contents to the server? – greenapps Oct 25 '16 at 09:27
  • if paths on device cannot be read by servers on internet, what should i do to read file from device and send it to server as parameter value.? – benjamin Oct 25 '16 at 09:34
  • You have to put the complete contents of the file in your soap object i think. Your ksoap client should send the file embedded in the soap request. But look at the API for this soap server. It will tell you how to do it. – greenapps Oct 25 '16 at 09:45
  • i think i have to use fileinputstream method to read file path, convert it into byte array format and then store it in string and send it as string to server. right? – benjamin Oct 25 '16 at 10:06
  • Very well possible. I dont know. Look at the API. In a String? I think you mean in a base64 encoded String? – greenapps Oct 25 '16 at 10:15
  • `convert it into byte array format`. You do not have to convert the bytes of the file. I would say 'put the bytes of the file in a byte array'. – greenapps Oct 25 '16 at 10:16
  • yes API needs to be changed, so that i can send base64toString format. but can you show me a code snippet where we can take filepath andconvert itto string? btw thanks a ton man. – benjamin Oct 25 '16 at 11:25
  • http://stackoverflow.com/questions/6058003/elegant-way-to-read-file-into-byte-array-in-java – greenapps Oct 25 '16 at 12:33
  • thank you but i used this code - File readpdfFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()+ "/NewPDF_.pdf"); String encodedBase64 = null; FileInputStream fileInputStreamReader = new FileInputStream(readpdfFile); byte[] bytes = new byte[(int)readpdfFile.length()]; fileInputStreamReader.read(bytes); encodedBase64 = new String(Base64.encodeToString(); is it correct way? – benjamin Oct 26 '16 at 05:32
  • You are doing nothing with the `bytes`. Please put code in an extra block in youf post. Its pretty unreadable in a comment. – greenapps Oct 26 '16 at 08:13
  • And if this is your first base64 encoding you should exercise with directly decoding the encoded string in order to see if you get the same amount and the same bytes back. – greenapps Oct 26 '16 at 08:16
  • yes its first for me. got it. thanks. – benjamin Oct 26 '16 at 09:38

0 Answers0