我正在尝试上传保存在手机内存中的图像,点击Android应用程序到云服务,我正在使用Kinvey这样做。但我面临着一些问题。
每次运行包含上传部分的代码时,都会遇到异常。我正在上传“.png”类型的图片。与Google Cloud Platform中的转换不同,任何转换为blob都不是必需的过程。
这是我的.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
}
});`
现在,虽然ping调用给了我一个成功的响应,但上传部分给了我一个错误。
E / Activity文件:无法上传文件。 com.kinvey.java.KinveyException: 原因:当前没有用户登录。
我在kinvey的讨论平台上也在这里搜索了很多关于这个主题的内容。但我仍然被卡住了。我不知道我哪里出错或者我可能错过了什么。
如果有人成功设法通过kinvey上传图片,那么请帮助我。
答案 0 :(得分: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
的更多信息答案 1 :(得分:0)
Sharmistha,
是的,每个应用操作都需要一个活动的用户上下文。 因此,您需要在应用程序中登录,然后上传文件。
请查看以下内容: http://devcenter.kinvey.com/android/guides/users#ActiveUser http://devcenter.kinvey.com/android/guides/files#Uploading
谢谢, Pranav Kinvey