所以我将托管包从bluehost移到namecheap。我目前正在开发一个针对大学问题的Android应用程序。图像上传在bluehost webhost上运行良好。但是,当我尝试使用相同的技术时,我遇到了错误。
我做了一些调试并得出结论,它是服务器端相关的,因为它是相同的代码,但参数已更改,Android上没有任何内容引发任何错误。条目将添加到数据库中,但图像不会上传(注册系统)。
错误:
413 Request Entity Too Large
Request Entity Too Large
The requested resource does not allow request data with GET requests, or the amount of data provided in the request exceeds the capacity limit.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
PHP代码:
$user = $_POST['userName'];
$base = $_REQUEST['image'];
$binary = base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
mkdir('../usr/'.$user);
$file = fopen('../usr/'.$user.'/display_picture.png', 'wb');
fwrite($file, $binary);
fclose($file);
Java代码:(只是加入)
public void uploadDisplayPicture(final ProgressDialog uploadingImage) {
final String UPLOAD_DISPLAY_PICTURE = "Upload Display Picture";
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
Log.d(UPLOAD_DISPLAY_PICTURE,"Do In Background Running");
InputStream is;
try {
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("userName", registrationDetails[0]));
nameValuePairs.add(new BasicNameValuePair("image", encodedString));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Config.IP + Config.DISPLAY_PHOTO_PATH);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) sb.append(line + "\n");
String resString = sb.toString();
is.close();
Log.d("Http Post Response:", response.toString());
Log.d("Http Response:", resString);
} catch (Exception e) {
System.out.println("Error: " + e);
}
return "";
}
@Override
protected void onPostExecute(String msg) {
Log.d(UPLOAD_DISPLAY_PICTURE, "On Post Execute Running");
super.onPostExecute(msg);
uploadingImage.setMessage("Registering User Details...");
new registerUserDetails().execute(registrationDetails);
}
}.execute(null, null, null);
}