2017-03-28 9 views
-1

アンドロイドアプリからサーバーにpdfとテキストを送信しようとすると、テキストの送信に成功しました。問題は、私はPDFファイルを送信することはできませんですが、私はアンドロイドのコードやPHPコードに問題はそう誰もが アンドロイドコードこの問題で私を助けることができるしていない場合サーバーにpdfを送信し、データベースに保存します

private class postData extends AsyncTask<String, Void, String> { 


    EditText email = (EditText) myView.findViewById(R.id.email); 
    EditText phone = (EditText) myView.findViewById(R.id.email); 
    String eemail=email.getText().toString(); 
    String pphone=phone.getText().toString(); 
    EditText first = (EditText) myView.findViewById(R.id.firstname); 
    EditText second= (EditText) myView.findViewById(R.id.lastname); 
    String firstname=first.getText().toString(); 
    String lastname=second.getText().toString(); 

    @Override 
    protected String doInBackground(String... params) { 

     HttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httppost = new HttpPost("http://phone.tmsline.com/api/request_job"); 
     String json = ""; 
     String responseStr=""; 
     String result="true"; 


     try { 
      // Add your data 

      File uploadFile1 = new File("/sdcard/Download/Testing foundation.pdf"); 

      FileBody fileBody = new FileBody(uploadFile1 , ContentType.DEFAULT_BINARY); 
      MultipartEntityBuilder builder = MultipartEntityBuilder.create(); 


      builder.addPart("cv",new FileBody(uploadFile1)); 
      builder.addPart("email", new StringBody(eemail)); 
      builder.addPart("phone", new StringBody(pphone)); 
      builder.addPart("firstname", new StringBody(firstname)); 
      builder.addPart("lastname", new StringBody(lastname)); 
      HttpEntity entity = builder.build(); 


      httppost.setEntity(entity); 

      try { 
       httpclient.execute(httppost); 
       // filetest(); 
      } catch (UnsupportedEncodingException e) { 
       e.printStackTrace(); 

      } 


      // Execute HTTP Post Request 

      HttpResponse response = httpclient.execute(httppost); 

      responseStr = EntityUtils.toString(response.getEntity()); 




     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      Log.i("HTTP Failed", e.toString()); 

     } 
     return responseStr; 
    } 
    protected void onPostExecute(String responseStr) { 
     super.onPostExecute(responseStr); 

     String result=""; 
     String test=""; 
     String msg="msg"; 
     int x=1; 

     Toast.makeText(getActivity(),responseStr,Toast.LENGTH_LONG).show(); 
     try { 
      JSONArray pp=new JSONArray(responseStr); 
      result = pp.getString(x)  Toast.makeText(getActivity(),result,Toast.LENGTH_LONG).show(); 






      //result is key for which you need to retrieve data 
     } catch (JSONException e) { 
      e.printStackTrace(); 
      Toast.makeText(getActivity(),e.toString(),Toast.LENGTH_LONG).show(); 

     } 



    } 

PHPコード

public function add_resume(Request $request){ 
    $resume = new Resume; 
    $resume->first_name = $request->firstname; 
    $resume->last_name = $request->lastname; 
    $resume->phone = $request->phone; 
    $resume->email = $request->email; 
    $file = $request->file('cv'); 
    $ext = $file->guessExtension(); 
    $ext=".".$ext; 
    $filename=md5(time().mt_rand()); 
    $file->move(storage_path('app/public/uploads'),$filename.$ext); 
    $resume->cv = $filename.$ext; 
    $resume->save(); 
    return response()->json(['cv','1']); 
} 
+0

[mcve]を作成してください。 – dash2

答えて

0
public void onBindViewHolder(final MyAttachmentViewHolder holder, final int position) { 
     attachments=alist.get(position); 
     holder.filename.setText(attachments.get(FragmentAssignmentDetails.FILE)); 
     holder.viewButton.setOnClickListener(new View.OnClickListener() { 
               @Override 
               public void onClick(View v) { 
                boolean internet = new Internetcheck(contex).isOnline(); 
                if (internet) { 
                 attachments=alist.get(position); 
                 String filename = attachments.get(FragmentAssignmentDetails.FILE); 
                 Bundle bundle = new Bundle(); 
                 filename.toLowerCase(); 
                 if (filename.endsWith("jpeg") || filename.endsWith("jpg") || filename.endsWith("png") || filename.endsWith("JPG") || filename.endsWith("PNG") || filename.endsWith("JPEG")) { 
                  bundle.putString("filetype", "imagefile"); 

                 } else if (filename.endsWith("flv") || filename.endsWith("mp4") || filename.endsWith("mov")) { 
                  bundle.putString("filetype", "videofile"); 
                 } else { 
                  bundle.putString("filetype", "noimage"); 
                 } 
                 Fragment fragment = new FragmentWebview(); 
                 bundle.putString("link", (url+filename)); 
                 fragment.setArguments(bundle); 

                 android.support.v4.app.FragmentTransaction fragmentTransaction = ((android.support.v4.app.FragmentActivity) contex).getSupportFragmentManager().beginTransaction(); 
                 fragmentTransaction.setTransition(android.support.v4.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 
                 fragmentTransaction.replace(R.id.container_body, fragment); 
                 fragmentTransaction.addToBackStack(null); 
                 fragmentTransaction.commit(); 

                } else { 
                 Toast.makeText(contex, "No internet", Toast.LENGTH_SHORT).show(); 

                } 
               } 
              } 
     ); 
     holder.downloadButton.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       attachments=alist.get(position); 
       filename = attachments.get(FragmentAssignmentDetails.FILE); 
       String filelink = url+filename; 
       sdCard = Environment.getExternalStorageDirectory(); 
       directory = new File(sdCard.getAbsolutePath() + "/" + contex.getString(R.string.sdirname) + "/" + foldername + "/" + filename); 
       String str = directory.getAbsolutePath().toString(); 
       if (directory.exists()) { 
        Intent intent = new Intent(Intent.ACTION_VIEW); 
        if (str.endsWith("pdf") || str.endsWith("PDF")) { 
         intent.setDataAndType(Uri.fromFile(directory), "application/pdf"); 
         intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
         contex.startActivity(intent); 
        } else if (str.endsWith("docx") || str.endsWith("doc")) { 
         intent.setDataAndType(Uri.fromFile(directory), "application/msword"); 
         contex.startActivity(intent); 
         intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
        } else if (str.endsWith("jpeg") || str.endsWith("jpg") || str.endsWith("png") || str.endsWith("JPG") || str.endsWith("PNG") || str.endsWith("JPEG")) { 
         intent.setDataAndType(Uri.fromFile(directory), "image/*"); 
         intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
         contex.startActivity(intent); 
        } 
        else{ 
         Toast.makeText(contex, "App not found", Toast.LENGTH_SHORT).show(); 
        } 
       } 
       else { 
        internet = new Internetcheck(contex).isOnline(); 
        if (internet) { 
         task = (DownloadFileFromURL) new DownloadFileFromURL(contex).execute(filelink); 
        } 
        else { 
         Toast.makeText(contex, "No internet", Toast.LENGTH_SHORT).show(); 
        } 
       } 


      } 
     }); 
    } 
関連する問題