【发布时间】:2015-10-20 11:02:01
【问题描述】:
大家好!
我有一个jpg image stored on my device,我想要sent it to server(mywebsite.com/api.php)。我想使用volley library,因为它是由谷歌官方android开发者制作的,我想他们会尽快将它添加到sdk中。
现在我正在使用以下代码将字符串发送到服务器:
postRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
// code here for response
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// code here for error response
}
}
) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
// the POST parameters:
params.put("key", "myApiKey");
params.put("data","stringOfMyData");
return params;
}
};
如何使用 volley 库将 jpg 发送到服务器?每次我发送一些东西时,我都需要将它与 API 密钥一起发送,以便将信息接收到服务器,所以我不能将 Map<String, String> 更改为 Map<String, File>,因为我的 API 密钥是一个字符串。
我读到有一种解决方案可以将我的图像更改为byte[] array,然后将其转换为base64 string 格式,但如果可能的话,我想避免这种情况。
有没有其他解决方案可以在不将其转换为base64 string 的情况下发送图像?
欢迎任何参考或建议!提前致谢!
【问题讨论】:
标签: android jpeg android-volley android-networking