2016-11-19 37 views
1

我想上傳一個圖像,保存在我的手機的內存,點擊一個Android應用程序到雲服務,並使用Kinvey這樣做。但我正面臨着一些問題。試圖上傳一個圖像從Android應用程序到雲使用kinvey

每次我運行包含上傳部分的代碼時,都會遇到異常。我正在上傳「.png」類型的圖片。與谷歌雲平臺不同,任何轉換爲​​斑點的過程都不是必需的過程。

這裏是我的.java代碼 -

`Client mKinveyClient = new Client.Builder(APP_KEY, SECRET_KEY, this.getApplicationContext()).build(); 
    mKinveyClient.enableDebugLogging(); 

    mKinveyClient.ping(new KinveyPingCallback() { 
     public void onFailure(Throwable t) { 
      Log.e(TAG, "Kinvey Ping Failed", t); 
     } 
     public void onSuccess(Boolean b) { 

      Log.d(TAG, "Kinvey Ping Success"); 
     } 
    }); 

    java.io.File file = new java.io.File(Environment.getExternalStorageDirectory().getPath() + "/Camera/" + "IMG_20161115_193353.jpg"); 

    mKinveyClient.file().upload(file, new UploaderProgressListener() { 
      public void onSuccess(Void result) { 
      Log.i(TAG, "successfully upload file"); 
     } 

     @Override 
     public void onSuccess(FileMetaData fileMetaData) { 
       Log.i(TAG, "successfully uploaded file"); 
      } 
     @Override 
     public void onFailure(Throwable error) { 
      Log.e(TAG, "failed to upload file.", error); 
      } 
     @Override 
     public void progressChanged(MediaHttpUploader uploader) throws IOException { 
      Log.i(TAG, "upload progress: " + uploader.getUploadState());      // all updates to UI widgets need to be done on the UI thread 
      } 
     });` 

如今,雖然平安電話是給我一個成功的響應,上傳的部分是給我的錯誤。

E /活動文件:未能上傳文件。 com.kinvey.java.KinveyException: 理由:目前沒有用戶登錄

我搜索關於這個主題很多,在kinvey的討論平臺,在這裏太。但我仍然堅持。我不知道我要去哪裏錯,或者我可能會錯過什麼。

如果有人已經成功地通過kinvey上傳圖片,請幫助我。

回答

0

任何類型的Kinvey操作必須通過登錄用戶提供。 在開始I/O任何信息之前,您必須註冊(或登錄)。

mKinveyClient.user().create("username", "password", new KinveyUserCallback()) { 
    @Override 
    public void onFailure(Throwable t) { 
     CharSequence text = "Could not sign up."; 
     Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show(); 
    } 
    @Override 
    public void onSuccess(User u) { 
     //here we go on uploading file 
    } 
}); 

您可以找到有關用戶的詳細信息here

相關問題