2017-07-26 34 views
0

你好我的工作Next Cloud API,而我想從我的設備上傳一張圖片爲:操作完成,HTTP狀態代碼409(失敗)

uploadButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      showFileChooser(); 
     } 
    }); 

    private void showFileChooser() { 
     Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
     intent.setType("*/*"); 
     intent.addCategory(Intent.CATEGORY_OPENABLE); 

     try { 
      startActivityForResult(
      Intent.createChooser(intent, "Select a File to Upload"),FILE_SELECT_CODE); 
     } catch (android.content.ActivityNotFoundException ex) { 
      // Potentially direct the user to the Market with a Dialog 
      Toast.makeText(this, "Please install a File Manager.", 
       Toast.LENGTH_SHORT).show(); 
     } 
    } 

和對活動的結果是:

 @Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    switch (requestCode) { 
     case FILE_SELECT_CODE: 
      if (resultCode == RESULT_OK) { 
       try { 
        // Get the Uri of the selected file 
        Uri uri = data.getData(); 
        // Get the path 
        String path = getPath(MainActivity.this, uri); 
        File fi = new File(path); 

        //set the image to image view 
        iv.setImageURI(Uri.fromFile(fi)); 

        Date lastModDate = new Date(fi.lastModified()); 
        startUpload(fi, "/testfolder", getMimeType2(Uri.fromFile(fi)),lastModDate.toString()); 
        Log.e(TAG, "file " + fi.toString() + " remote path " + mServerUri + " mime " + getMimeType2(Uri.fromFile(fi))+" date "+lastModDate.toString()); 
       } catch (Exception e) { 
        Log.e(TAG, "eee " + e.toString()); 
       } 
      } 
      break; 
    } 
    super.onActivityResult(requestCode, resultCode, data); 
} 

public static String getPath(Context context, Uri uri) throws URISyntaxException { 
    if ("content".equalsIgnoreCase(uri.getScheme())) { 
     String[] projection = {"_data"}; 
     Cursor cursor = null; 

     try { 
      cursor = context.getContentResolver().query(uri, projection, null, null, null); 
      int column_index = cursor.getColumnIndexOrThrow("_data"); 
      if (cursor.moveToFirst()) { 
       return cursor.getString(column_index); 
      } 
     } catch (Exception e) { 
      // Eat it 
     } 
    } else if ("file".equalsIgnoreCase(uri.getScheme())) { 
     return uri.getPath(); 
    } 

    return null; 
} 

雖然我只是用api documentation創建一個新文件夾,它的工作原理以及良好並創建了一個文件夾!儘管每個這樣的工作都很好,就像從Next Cloud中讀取文件一樣!

的問題是從設備的圖片上傳!我收到以下錯誤,而我試圖上傳:

Operation finished with HTTP status code 409 (fail) 

我現在不知道我已經做錯了,可有人請提供有關正在做什麼錯誤的一些想法!

回答

1

HTTP錯誤409意味着存在與服務器上的資源confict。 您應該檢查服務器的響應以瞭解如何解決該問題。 更多信息:https://httpstatuses.com/409