java - 如何在项目位置创建的新文件夹中上传文件?
问题描述
我正在使用 API,我需要将 Base 64 转换为图像,并且需要将该图像存储在服务器中的某个位置,以便移动应用程序可以读取路径并从那里显示图像?如何上传文件并返回文件路径,如
http://localhost:8080/xxxx.jpg
注意:我没有使用任何 JSP 或 servlet。
提前致谢 !!
解决方案
import java.io.ByteArrayInputStream;
import sun.misc.BASE64Decoder;
def sourceData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAYAAAA+VemSAAAgAEl...==';
// tokenize the data
def parts = sourceData.tokenize(",");
def imageString = parts[1];
// create a buffered image
BufferedImage image = null;
byte[] imageByte;
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(imageString);
ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bis);
bis.close();
File f = new File("D:\\Image\\Output.jpg"); //output file path
ImageIO.write(image, "jpg", f);
推荐阅读
- python - python - 当使用popen运行或在子进程库中运行时,如何在自己的行上打印python中的输入提示?
- regex - 让浏览器忽略 URL 中间的特定字符串的方法?
- python - ImportError:无法从“setuptools”导入名称“Feature”
- android-9.0-pie - (Termux:API)中的“termux-battery-status”命令不起作用
- javascript - 共享 React 组件的开放式样式
- python - 使用 KNearestNeighbors 绘制 Iris 数据集的决策边界的问题
- firebase - 无法在firebase数据库中读取和写入数据
- android-studio - 如何更改复选框背景圆圈的颜色?
- angular - 如何制作调用不同服务的通用方法
- angular - 没有从 nativescript-mediafilepicker 检索到 rawData