2017-09-07 145 views
0

我想送存儲在內部存儲(InternalStrorage/PDF/OCK.pdf)的Android使用凌空

我已經通過此功能,發送字符串數據使用的是Android亂射我的PHP服務器沒有問題的一個PDF文件發送PDF服務器:

private void upload(){ 

    StringRequest stringRequest = new StringRequest(Request.Method.POST, UploadURL, 
      new Response.Listener<String>() { 
       @Override 
       public void onResponse(String response) { 
        try { 
         JSONObject jsonObject = new JSONObject(response); 
         String Response = jsonObject.getString("response"); 
         Toast.makeText(getApplicationContext(),Response, Toast.LENGTH_LONG).show(); 
         selectedimage.setImageResource(0); 
         selectedimage.setVisibility(View.GONE); 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
      }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 

     } 
    } 
    ){ 
     @Override 
     protected Map<String, String> getParams() throws AuthFailureError { 
      Map<String, String> params = new HashMap<>(); 


      params.put("date",DateFormat.getDateTimeInstance().format(new Date()).toString()); 
          params.put("description",editTextDescription.getText().toString()); 
      params.put("statut", whatstatutis()); 
      params.put("action",editTextImediatActionTaken.getText().toString()); 
      return params; 
     } 



    }; 
    MySingleton.getInstance(getApplicationContext()).addTorequesteque(stringRequest); 

} 

我想在同一時間用我的數據發送PDF文件。

+0

嘗試使用多部分實體。文件可以使用多部分發送。 –

+0

@AshishJohn你有一個很好的教程或有用的鏈接? –

+0

也可以按照: 1.轉換PDF文件以字節數組 2.字節數組爲Base64編碼字節數組 字節[] encodedBytes = Base64.encodeBase64(origByteArr) 和 字符串base64Str =新字符串(encodedBytes); 使用任何可用的網絡庫發送它 – Napolean

回答

0

最後我找到解決方案。 1-的PDF僅轉換爲以字節數組 2-字節數組爲Base64 3-發送它像普通字符串

byte[] data = null; 
    File filessss = new File(Link_Of_The_PDF.pdf); 

    try { 

     data = FileUtils.readFileToByteArray(filessss); 

    } catch (IOException e) { 

     e.printStackTrace(); 

    } 

    return Base64.encodeToString(data, Base64.DEFAULT);