问题描述
我有一个applet使用J2D一个BufferedImage创建。
我要上传此BufferedImage HTTP POST @
I have a BufferedImage created using J2D in an applet.I want to upload this BufferedImage using HTTP Post @ http://localhost:3001/upload/file.
编辑:我有一个ROR服务器处理事物的服务器端,我找了Java code客户端
I have a ROR server handling the serverside of things, I am looking for the Java code for the client.
所有的例子我能找到包括上传文件。
All the examples I can find involve uploading Files.
有人知道如何上传一个BufferedImage?
Anybody know how to upload a BufferedImage?
干杯,
slotishtype
slotishtype
推荐答案
确定,因此,这里的code是C $ CS它为Base64字符串创建的BufferedImage EN $然后使用Apache公共图书馆的帖子字符串通过HTTP一个ROR服务器。
OK, So here is the code that creates the bufferedimage, encodes it as a Base64 string and then using the apache commons library posts the string over http to a ROR Server.
BufferedImage bi = new BufferedImage(110, 110, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bi.createGraphics();
AffineTransform saveTX = new AffineTransform();
saveTX.translate(translateX, translateY);
saveTX.scale(0.2, 0.2);
g2.setTransform(saveTX);
this.paint(g2);
ImageInputStream bigInputStream = ImageIO.createImageInputStream(bi);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bi, "BMP", baos);
byte[] bytes = baos.toByteArray();
String dataImg = new Base64().encodeBase64String(bytes);
PostMethod post = new PostMethod("http://localhost:3001/upload/file");
post.addParameter("upload[test]", dataImg);
HttpClient client = new HttpClient();
int status = client.executeMethod(post);
g2.dispose();
的ROR服务器只是简单地采用串,德codeS,并将其保存到硬盘....
The ROR server simply takes the string, decodes it and saves it to the harddrive....
require "base64"
class UploadController < ApplicationController
#Token = nil
skip_before_filter :verify_authenticity_token
def index
render :file => 'app\views\upload\uploadfile.html.erb'
end
def file
File.open('test.gif', 'wb') do|f|
f.write(Base64.decode64(params[:upload][:test]))
end
render :text => "File has been uploaded successfully"
end
结束
感谢您的帮助球员,
slotishtype
slotishtype
这篇关于HTTP的Java小程序后服务器 - 内部产生的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!