【问题标题】:How to Upload Files in a new folder created in a project location?如何在项目位置创建的新文件夹中上传文件?
【发布时间】:2019-03-29 21:40:50
【问题描述】:

我正在使用 API,我需要将 Base 64 转换为图像并且需要将该图像存储在服务器中的某个位置,以便移动应用程序可以读取路径并从那里显示图像?如何上传文件并返回文件路径如

http://localhost:8080/xxxx.jpg

注意:我没有使用任何 JSP 或 servlet。

提前致谢!!

【问题讨论】:

    标签: java jakarta-ee file-upload


    【解决方案1】:
    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);
    

    【讨论】:

      猜你喜欢
      • 2021-08-15
      • 1970-01-01
      • 2019-03-17
      • 1970-01-01
      • 1970-01-01
      • 2014-01-22
      • 1970-01-01
      • 2022-10-04
      • 2017-01-09
      相关资源
      最近更新 更多