zoukankan      html  css  js  c++  java
  • Rop 文件上传解决思路

    由于服务请求报文是一个文本,无法直接传送二进制的文件内容,因此必须采用某种
    转换机制将二进制的文件内容转换为字符串。Rop 采用如下的方式对上传文件进行编码:
    <fileType>@<BASE64( 文件内容 )>
    <fileType>代表文件类型,文件内容采用 BASE64 算法进行编码,这样二进制的文件
    内容就可以转换为一个字符串,两者“@”字符分隔。服务端接收到上传的文件后,即可
    解析出文件的类型和文件的内容。
    Rop 定义了一个 UploadFile,代表一个上传的文件,来看一下 UploadFile 的定义:

    package com.rop.request;
    import com.rop.annotation.IgnoreSign;
    import org.springframework.util.FileCopyUtils;
    import java.io.File;
    import java.io.IOException;
    @IgnoreSign ①
    public class UploadFile {
      private String fileType;
      private byte[] content;
      public UploadFile(String fileType, byte[] content) {
        this.content = content;
        this.fileType = fileType;
      }
      public UploadFile(File file) {
        try {
          this.content = FileCopyUtils.copyToByteArray(file);
          this.fileType = file.getName().substring(file.getName().lastIndexOf('.')+1);
          } catch (IOException e) {
            throw new RuntimeException(e);
          }
      }
      public String getFileType() {
        return fileType;
      }
      public byte[] getContent() {
        return content;
      }
    }
  • 相关阅读:
    charles 安装、破解、简单介绍
    8、postman中 转码生成python-requests接口请求代码,并定义一个获取及请求的方法
    json 序列化和反序列化(针对python数据类型)
    leetcode 35.搜索插入位置
    leetcode 27.移除元素
    js 中的数组方法
    js判断小数点后几位小数
    leetcode 15.三数之和
    leetcode 1.两数之和
    leetcode 680.验证回文字符串
  • 原文地址:https://www.cnblogs.com/smile361/p/4435189.html
Copyright © 2011-2022 走看看