2017-05-25 57 views
-2

我試圖從存儲器上傳映像到服務器。我在這裏做錯了什麼?我需要爲此使用PHP腳本嗎?無法使用快速Android網絡庫將映像上載到服務器

私有類UploadImage擴展的AsyncTask {

File picPath; 
    String picName; 

    public UploadImage(File picPath, String picName){ 
     this.picPath= picPath; 
     this.picName = picName; 
    } 

    @Override 
    protected Void doInBackground(Void... params) { 
     String uril = getResources().getString(R.string.ServerPath) + "MyFiles/" + picName; 
     AndroidNetworking.upload(uril) 
       .addMultipartFile(picName, picPath) 
       .addMultipartParameter("key","value") 
       .setPriority(Priority.MEDIUM) 
       .build() 
       .setUploadProgressListener(new UploadProgressListener() { 
        @Override 
        public void onProgress(long bytesUploaded, long totalBytes) { 
         if (bytesUploaded == totalBytes){ 
          Toast.makeText(getApplicationContext(), "Image Uploaded!",Toast.LENGTH_SHORT).show(); 
         } 

        } 
       }); 

     return null; 
    } 

    @Override 
    protected void onPostExecute(Void aVoid) { 
     super.onPostExecute(aVoid); 
     Toast.makeText(getApplicationContext(), "Uploaded!",Toast.LENGTH_SHORT).show(); 

    } 
} 

回答

0

如果你想上傳圖片到PHP服務器,那麼你必須使用PHP代碼。在this例子,它說明如何出現在庫應用程序上傳圖片到PHP服務器

0

請注意,你必須考慮載爲POST庫,但如果你需要使用「把」方法的API調用將失敗,爲你提供400個不好的請求。

相關問題