【发布时间】:2017-05-25 16:07:00
【问题描述】:
我正在尝试将图像从存储上传到服务器。我在这里做错什么了吗?我需要为此使用 PHP 脚本吗?
私有类 UploadImage 扩展 AsyncTask{
File picPath;
String picName;
public UploadImage(File picPath, String picName){
this.picPath= picPath;
this.picName = picName;
}
@Override
protected Void doInBackground(Void... params) {
String uril = getResources().getString(R.string.ServerPath) + "MyFiles/" + picName;
AndroidNetworking.upload(uril)
.addMultipartFile(picName, picPath)
.addMultipartParameter("key","value")
.setPriority(Priority.MEDIUM)
.build()
.setUploadProgressListener(new UploadProgressListener() {
@Override
public void onProgress(long bytesUploaded, long totalBytes) {
if (bytesUploaded == totalBytes){
Toast.makeText(getApplicationContext(), "Image Uploaded!",Toast.LENGTH_SHORT).show();
}
}
});
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Toast.makeText(getApplicationContext(), "Uploaded!",Toast.LENGTH_SHORT).show();
}
}
【问题讨论】:
标签: android networking android-asynctask image-uploading