用凌空上传多个图像? [英] Uploading multiple images with volley?
问题描述
我已经在SO和其他内容中经历了很多帖子。但是我无法获得任何最新的官方或其他帖子,其中不包含任何已弃用的代码,用于使用volley上传多个图像。我来了解Apache HTTP Client删除并在新的Android M中相关,而不是在下面使用。
android {
useLibrary'org .apache.http.legacy'
}
所以,任何人都可以帮助我使用新的更新已弃用的少量排球类进行多个图像上传?
您可以使用这里。这是一个非官方镜像,修复了一些小错误,源代码会定期与官方排球库同步。 / p>
for Gradle
compile'com .mcxiaoke.volley:library:1.0.19'
或者您可以从这里
现在,您可以使用以下附加课程,在<$ c的帮助下使用排球进行多部分请求$ c> $ code> org.apache.http.entity.mime 中的$ c> MultipartEntityBuilder ,没有任何弃用的代码。
样本用量
// Auth标头
Map< String,String> mHeaderPart = new HashMap<>();
mHeaderPart.put(Content-type,multipart / form-data;);
mHeaderPart.put(access_token,accessToken);
//文件部分
Map< String,File> mFilePartData = new HashMap<>();
mFilePartData.put(file,new File(mFilePath));
mFilePartData.put(file,new File(mFilePath));
//字符串部分
Map< String,String> mStringPart = new HashMap<>();
mStringPart.put(profile_id,1);
mStringPart.put(imageType,ProfileImage);
CustomMultipartRequest mCustomRequest = new CustomMultipartRequest(method,mContext,url,new Response.Listener< JSONObject>(){
@Override
public void onResponse(JSONObject jsonObject){
listener.onResponse(jsonObject);
}
},new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError volleyError){
listener .onErrorResponse(volleyError);
}
},mFilePartData,mStringPart,mHeaderPart);
您可以使用 httpmime-4.3.5.jar
和 httpcore-4.3.2.jar
用于访问 MultipartEntityBuilder
以及用于制作的其他方法如果您的定位API 23及更高版本,请求或在您的gradle中添加以下内容。
android {
useLibrary'org.apache.http.legacy'
}
任何方式我都使用上面提到的jar,它的效果就像Android M中的魅力一样。
更新
请注意, com。 mcxiaoke.volley:library:1.0.19
已弃用且不再维护,请使用 jCenter
中的正式版。
编译'com.android.volley:排球:1.0.0'
I have gone through a lot of post in SO and other tuts as well.But i couldn't get any latest official or other post that doesn't contain any deprecated code for uploading multiple images using volley.I came to know Apache HTTP Client removal and related in new android M and preferred to use below instead.
android {
useLibrary 'org.apache.http.legacy'
}
So, can any one help me out for doing multiple image upload with new updated deprecated less volley class ?
You can use the latest version of volley from here.It's an unofficial mirror with some minor bug fix and the source code will synchronize periodically with the official volley repository.
for Gradle
compile 'com.mcxiaoke.volley:library:1.0.19'
or you can download the compiled version from here
Now you can use the below attached class for making multipart request using volley by the help of MultipartEntityBuilder
in org.apache.http.entity.mime
without having any deprecated code.
Sample usage
//Auth header
Map<String, String> mHeaderPart= new HashMap<>();
mHeaderPart.put("Content-type", "multipart/form-data;");
mHeaderPart.put("access_token", accessToken);
//File part
Map<String, File> mFilePartData= new HashMap<>();
mFilePartData.put("file", new File(mFilePath));
mFilePartData.put("file", new File(mFilePath));
//String part
Map<String, String> mStringPart= new HashMap<>();
mStringPart.put("profile_id","1");
mStringPart.put("imageType", "ProfileImage");
CustomMultipartRequest mCustomRequest = new CustomMultipartRequest(method, mContext, url, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
listener.onResponse(jsonObject);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
listener.onErrorResponse(volleyError);
}
}, mFilePartData, mStringPart, mHeaderPart);
Either you can use httpmime-4.3.5.jar
and httpcore-4.3.2.jar
for getting access of MultipartEntityBuilder
and other methods which is used to make the request or add the following in your gradle if your targeting API 23 and above.
android {
useLibrary 'org.apache.http.legacy'
}
Any way I'm using the mentioned jar's and it's works like a charm in Android M also.
Update
Please note, com.mcxiaoke.volley:library:1.0.19
deprecated and no longer being maintained, please use official version from jCenter
.
compile 'com.android.volley:volley:1.0.0'
这篇关于用凌空上传多个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!