我正在尝试通过 HttpURLConnection 编写图像。
我知道如何写文字,但我在尝试写图片时遇到了真正的问题
我已使用 ImageIO 成功写入本地 HD:
但我试图在 url 上通过 ImageIO 编写 Image 并且失败了
URL url = new URL(uploadURL);
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", "multipart/form-data;
boundary=" + boundary);
output = new DataOutputStream(connection.getOutputStream());
output.writeBytes("--" + boundary + "\r\n");
output.writeBytes("Content-Disposition: form-data; name=\"" + FIELD_NAME + "\";
filename=\"" + fileName + "\"\r\n");
output.writeBytes("Content-Type: " + dataMimeType + "\r\n");
output.writeBytes("Content-Transfer-Encoding: binary\r\n\r\n");
ImageIO.write(image, imageType, output);
uploadURL 是服务器上的 ASP 页面的 URL,该页面将使用“content-Disposition:part.xml”中给出的文件名上传图像。
现在当我发送这个然后asp页面找到请求并找到文件名。但没有找到要上传的文件。
问题是,当 ImageIO 在 URL 上写入时,ImageIO 正在写入的文件的名称是什么,
所以请帮助我 ImageIO 将如何在 URLConnection 上写入图像以及我如何知道我必须在 asp 页面中使用来上传文件的文件的名称
感谢您花时间阅读这篇文章 Dilip Agarwal