Java 将位图从android上传到服务器会产生一个不可修复的文件

Java 将位图从android上传到服务器会产生一个不可修复的文件,java,android,bitmap,wamp,Java,Android,Bitmap,Wamp,因此,我使用了stackoverflow中的一些代码,该代码使用HttpURLConnection将位图从Android发送到本地WAMP服务器。我唯一的问题是发送的数据不能被图像查看器打开。我觉得这与我发送数据的方法有关 HttpURLConnection httpUrlConnection = null; URL url = new URL(ip+urls[0]); httpUrlConnection = (HttpURLConnection) url.openCon

因此,我使用了stackoverflow中的一些代码,该代码使用HttpURLConnection将位图从Android发送到本地WAMP服务器。我唯一的问题是发送的数据不能被图像查看器打开。我觉得这与我发送数据的方法有关

    HttpURLConnection httpUrlConnection = null;
    URL url = new URL(ip+urls[0]);
    httpUrlConnection = (HttpURLConnection) url.openConnection();
    httpUrlConnection.setUseCaches(false);
    httpUrlConnection.setDoOutput(true);

    httpUrlConnection.setRequestMethod("POST");
    httpUrlConnection.setRequestProperty("Connection", "Keep-Alive");
    httpUrlConnection.setRequestProperty("Cache-Control", "no-cache");
    httpUrlConnection.setRequestProperty(
            "Content-Type", "multipart/form-data;boundary=" + this.boundary);

    DataOutputStream request = new DataOutputStream(
            httpUrlConnection.getOutputStream());

    request.writeBytes(this.twoHyphens + this.boundary + this.crlf);
    request.writeBytes("Content-Disposition: form-data; name=\"" +
            this.attachmentName + "\";filename=\"" +
            this.attachmentFileName + "\"" + this.crlf);
    request.writeBytes(this.crlf);

    int bytes = bitmap.getByteCount();
    Log.e("bitmap bytes",Integer.toString(bytes));
    ByteBuffer buffer = ByteBuffer.allocate(bytes);
    bitmap.copyPixelsToBuffer(buffer);
    byte[] pixels = buffer.array();

    request.write(pixels);
    request.writeBytes(this.crlf);
    request.writeBytes(this.twoHyphens + this.boundary +
            this.twoHyphens + this.crlf);
    request.flush();
    request.close();

    //Response
    InputStream responseStream = new
            BufferedInputStream(httpUrlConnection.getInputStream());

    BufferedReader responseStreamReader =
            new BufferedReader(new InputStreamReader(responseStream));

    String line = "";
    StringBuilder stringBuilder = new StringBuilder();

    while ((line = responseStreamReader.readLine()) != null) {
        stringBuilder.append(line).append("\n");
    }
    responseStreamReader.close();

    String response = stringBuilder.toString();
    responseStream.close();
    httpUrlConnection.disconnect();
    return response;
我已经检查了文件大小,它们是相同的。我计划在将来将图像发送回我的android设备,但是我想首先确保上传部分工作正常。如果该文件应该是不可修复的,并且我理解的代码是错误的,我为浪费的时间道歉