我正在开展一个用户注册是一个小模块的项目。在哪里我可以使用少量参数,如姓名,电子邮件,联系方式,年龄,地址和& profile_pic。
//Here is my Android part Code
Where Profile_pic is the compressed byte[] of an image
这是我的byte []压缩方法
public static byte[] compress(byte[] data) throws IOException {
Deflater deflater = new Deflater();
deflater.setInput(data);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
deflater.finish();
byte[] buffer = new byte[1024];
while (!deflater.finished()) {
int count = deflater.deflate(buffer);
outputStream.write(buffer, 0, count);
}
outputStream.close();
byte[] output = outputStream.toByteArray();
return output;
}
Android Volley Reuest将用户数据存储到服务器
public void addUser(final String name, final String email, final String mobile, final String password, final String dob,
final String gender, final String address, final String profile_pic, final String latLng,
final String city, final String state, final String country, final String postalcode) {
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_REQUEST_SMS, new Response.Listener<String>() {
public String addresse;
@Override
public void onResponse(String response) {
System.out.println("1");
try {
JSONObject responseObj = new JSONObject(response);
boolean error = responseObj.getBoolean("error");
String message = responseObj.getString("message");
if (!error) {
......
} else {
Toast.makeText(context,
"Error: " + message,
Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
Toast.makeText(context,
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context,
error.getMessage() , Toast.LENGTH_SHORT).show();
}
}) {
/**
* Passing user parameters to our server
* @return
*/
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("name", name);
params.put("email", email);
params.put("mobile", mobile);
params.put("password", password);
params.put("dob", dob);
params.put("gender", gender);
params.put("address", address);
params.put("profile_pic", profile_pic);
params.put("latLng", latLng);
params.put("color", String.valueOf(color));
params.put("user_level", "patient");
params.put("city", city);
params.put("state", state);
params.put("country", country);
params.put("postalcode", postalcode);
return checkParams(params);
}
private Map<String, String> checkParams(Map<String, String> map) {
for (Map.Entry<String, String> pairs : map.entrySet()) {
if (pairs.getValue() == null) {
map.put(pairs.getKey(), "");
}
}
return map;
}
};
strReq.setShouldCache(false);
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq);
}
这是我上传图片的PHP代码
$file_upload_url = __DIR__."/Upload/". $target_path;
// Get file name posted from Android App
$filename = 'user_'.$name.'_Profilepic'.'.png';
//check if the directory exists
if(!file_exists($file_upload_url)){
if(!mkdir($file_upload_url,0755,true)){
$error = error_get_last();
echo $error['message'];
echo 'failed';
}
}
// Decode Image
$binary=base64_decode($profile_pic);
header('Content-Type: image/png');
$file = fopen($file_upload_url.$filename, 'wb');
// Create File
fwrite($file, $binary);
fclose($file);
此处还有我的.htaccess文件设置
php_value memory_limit 128M
php_value post_max_size 500M
php_value upload_max_filesize 500M
以下问题是当我在localhost中运行整个程序时它按预期工作但在服务器上我从volley中得到此错误
BasicNetwork.performRequest: Unexpected response code 413
解决
问题在于服务器,因为它是共享主机,文件上传限制受到限制。
答案 0 :(得分:0)
就我而言,问题的答案是我使用的主机是共享主机。
帖子大小受到限制,因此我们将使用{p>更新.htaccess
文件
post_max_size
和upload_max_size
。