【发布时间】:2020-01-01 09:36:58
【问题描述】:
在我的应用程序中,我将图像上传到我的公司服务器
我正在努力解决的问题是我希望服务器在上传图片后响应上传成功或类似的内容, 目前上传有效,但我希望服务器响应成功/错误,我正在使用 koush Ion 进行上传,到目前为止我没有尝试过任何工作,并且尝试用谷歌搜索某些东西,但我找不到;找不到我要找的东西
图片上传代码
private void uploadImageToServer() {
try {
Bitmap bitmap=ImageLoader.init().from(selectedPhoto).requestSize(1024, 1024).getBitmap();
String encodedImage=ImageBase64.encode(bitmap);
Log.d(TAG, encodedImage);
CheckBox chk=findViewById(R.id.chk1);
if (chk.isChecked()) {
Uri.Builder builder=new Uri.Builder();
builder.scheme("https")
.authority("www.smartpractice.co.za")
.appendPath("files-upload-phone-app.asp")
.appendQueryParameter("MyForm", "Yes")
.appendQueryParameter("ClientID", clientId)
.appendQueryParameter("Username", email)
.appendQueryParameter("Pwd", pwd)
.appendQueryParameter("Category", Item)
.appendQueryParameter("ClientName", Item2)
.appendQueryParameter("NoEmail", "Yes");
myURL=builder.build().toString();
} else {
Uri.Builder builder4=new Uri.Builder();
builder4.scheme("https")
.authority("www.smartpractice.co.za")
.appendPath("files-upload-phone-app.asp")
.appendQueryParameter("MyForm", "Yes")
.appendQueryParameter("ClientID", clientId)
.appendQueryParameter("Username", email)
.appendQueryParameter("Pwd", pwd)
.appendQueryParameter("Category", Item)
.appendQueryParameter("ClientName", Item2)
.appendQueryParameter("NoEmail", "");
myURL=builder4.build().toString();
}
final ProgressDialog pd=new ProgressDialog(SecondActivity.this);
pd.setMessage("Uploading, Please Wait....");
pd.show();
File file=new File(selectedPhoto);
Ion.with(SecondActivity.this)
.load(myURL)
.uploadProgressDialog(pd)
.setMultipartFile("SP-LOG", "image/*", file)
.asString()
.setCallback(new FutureCallback<String>() {
@Override
public void onCompleted(Exception e, String result) {
Toast.makeText(SecondActivity.this, "Upload Successful", Toast.LENGTH_LONG).show();
pd.cancel();
}
});
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(), "No File Found", Toast.LENGTH_LONG).show();
}
}
【问题讨论】:
-
为了做到这一点,您的服务器 api 必须返回您想要显示的消息。然后您可以在 onCompleted 回调中访问结果,并可以执行类似这样的操作 result == "SUCCESS" 。
-
我已经编码了 3 周,你是怎么做到的?,非常感谢一个链接
-
那是你的服务器软件需要改变,你不能强迫服务器从客户端做你想做的事。