package test;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.codec.binary.Base32InputStream;
import org.apache.commons.codec.binary.Base64;
import org.junit.Test;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.util.FileCopyUtils;
import com.thoughtworks.xstream.core.util.Base64Encoder;
public class Base64传送图片 {
@Test
public void test() throws IOException{
Resource resource = new FileSystemResource("f:/29.jpg");
InputStream in = resource.getInputStream();
byte[] bs = FileCopyUtils.copyToByteArray(in);
String str = Base64.encodeBase64String(bs);
str="data:;base64,"+str;
System.out.println(str);
}
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.codec.binary.Base32InputStream;
import org.apache.commons.codec.binary.Base64;
import org.junit.Test;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.util.FileCopyUtils;
import com.thoughtworks.xstream.core.util.Base64Encoder;
public class Base64传送图片 {
@Test
public void test() throws IOException{
Resource resource = new FileSystemResource("f:/29.jpg");
InputStream in = resource.getInputStream();
byte[] bs = FileCopyUtils.copyToByteArray(in);
String str = Base64.encodeBase64String(bs);
str="data:;base64,"+str;
System.out.println(str);
}
}
前段直接获取 字符串填充到 标签 img 的 src属性中