操作已完成,HTTP 状态代码为 409(失败)
Operation finished with HTTP status code 409 (fail)
您好,我正在 Next Cloud Api,我正在尝试从我的设备上传图片:
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();
}
}
activity 结果如下:
@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)
我目前不知道我做错了什么,有人可以告诉我做错了什么吗!
HTTP错误409表示与服务器上的资源有冲突。
您应该检查服务器的响应以了解如何解决冲突。
更多信息:https://httpstatuses.com/409
您好,我正在 Next Cloud Api,我正在尝试从我的设备上传图片:
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();
}
}
activity 结果如下:
@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)
我目前不知道我做错了什么,有人可以告诉我做错了什么吗!
HTTP错误409表示与服务器上的资源有冲突。 您应该检查服务器的响应以了解如何解决冲突。 更多信息:https://httpstatuses.com/409