Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android 500图像上传错误_Java_Android_Multipartform Data - Fatal编程技术网

Java Android 500图像上传错误

Java Android 500图像上传错误,java,android,multipartform-data,Java,Android,Multipartform Data,我使用multipart时遇到500服务器错误。从iOS端上传图像时,使用相同的服务器代码。以下是我的多部分图像上传代码。服务器端使用PHP public PostFile(String requestURL) throws IOException { // creates a unique boundary based on time stamp URL url = new URL(requestURL); httpConn = (HttpURLConnection)

我使用multipart时遇到500服务器错误。从iOS端上传图像时,使用相同的服务器代码。以下是我的多部分图像上传代码。服务器端使用PHP

public PostFile(String requestURL)
throws IOException {
    // creates a unique boundary based on time stamp
    URL url = new URL(requestURL);
    httpConn = (HttpURLConnection) url.openConnection();
    httpConn.setUseCaches(false);
    httpConn.setDoOutput(true); // indicates POST method
    httpConn.setDoInput(true);
    httpConn.setRequestMethod("POST");
    httpConn.setRequestProperty("Connection", "Keep-Alive");
    httpConn.setRequestProperty("Cache-Control", "no-cache");
    httpConn.setRequestProperty(
        "Content-Type", "multipart/form-data;boundary=" + this.boundary);

    request = new DataOutputStream(httpConn.getOutputStream());
}
private void saveFile() {
    try {
        PostFile postFile = new PostFile(URL);
        //postFile.addFormField();
        postFile.addFormField("userId", "25");
        postFile.addFormField("accessToken", "h7lCesyM3XKjmjvjrdojzypUNPqA9MsB8PQIzZyWkYHtV43XcxPubUJ3EV8L");
        // contact.accumulate("files",imgData);
        postFile.addFormField("area", "dfs");
        postFile.addFilePart("test.jpeg", getFileFromBitmap(uri));
        postFile.finish();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
public void addFilePart(String fieldName, File uploadFile)
throws IOException {
    String fileName = uploadFile.getName();
    request.writeBytes(this.twoHyphens + this.boundary + this.crlf);
    request.writeBytes("Content-Disposition: form-data; name=\"" +
        fieldName + "\";filename=\"" +
        fileName + "\"" + this.crlf);
    request.writeBytes("Content-Type:  image/jpeg;" + this.crlf);
    request.writeBytes(this.crlf);

    // byte[] bytes = Files.readAllBytes(uploadFile.toPath());

    request.write(getBytesFromFile(uploadFile));
}

你也可以尝试发布php代码吗?你在php端设置了mimetype吗?@Vikrant我身上没有php代码。只是想确保服务器代码与iOS一起工作,而不是与Android一起工作。@JaiminThakkar Yes请检查您正在上载的文件大小。PHP代码可以接受多少大小的文件?有限制吗?尝试使用其他大小较小的文件。