• 2021.5.2 团队冲刺第五天


    今天做了文件下载

    下面是代码,下载还是根据url的定位

    public class DownloadAndUploadController {
    @Autowired
    private Upload upload;
    @Autowired
    private ImgMapper imgService;
    @RequestMapping("/UploadImg")
    @ResponseBody
    public String UploadImg(MultipartFile file, HttpServletResponse response, HttpServletRequest request) throws IOException {
    upload.uploadOne(staticConfig.UserMail,file);
    return staticMsg.successfulUpload;
    }

    @RequestMapping("/DownloadImg")
    @ResponseBody
    public byte[] downloadImg(String fileName) throws IOException {
    ImgObject imgObject=imgService.getImg(fileName);
    return FileUtil.readFileStreamByBytes(ImageCompression.ImgCompression(imgObject));
    }

    @RequestMapping("/DownloadRealImg")
    @ResponseBody
    public byte[] downloadRealImg(String fileName) throws IOException {
    ImgObject imgObject=imgService.getImg(fileName);
    return FileUtil.readFileByBytes(imgObject.getImgPath()+imgObject.getImgId()+imgObject.getImgName().substring(imgObject.getImgName().lastIndexOf(".")));
    }

    @RequestMapping("/getImgList")
    @ResponseBody
    public String getImgList(String class2){

    JSONArray jsonArray=new JSONArray();
    String str2="#";
    if(class2==null){
    System.out.println("class2==null");
    List<ImgObject> imgObjects=imgService.getUserAllImg(staticConfig.UserMail);
    for (ImgObject imgObject : imgObjects) {
    JSONObject jsonObject=new JSONObject();
    String str=imgObject.getImgPath();
    if(!str2.equals(imgObject.getImgPath().substring(str.indexOf("\")+ 1,str.indexOf("-")).substring(str.lastIndexOf("m")+2))){
    str2=str.substring(str.indexOf("\")+ 1,str.indexOf("-")).substring(str.lastIndexOf("m")+2);
    jsonObject.put("title",str2);
    jsonObject.put("img"," http://octoberimg.viphk.ngrok.org/SmartCloudAlbum_war_exploded/Cloud/DownloadImg?fileName="+imgObject.getImgId());
    jsonObject.put("imgID",imgObject.getImgId());
    jsonArray.add(jsonObject);
    }

    }
    return jsonArray.toJSONString();
    }else {
    System.out.println("class2="+class2);
    List<ImgObject> imgObjects=imgService.getUserImgByFile(staticConfig.UserMail,class2);
    if (class2.contains("-"))
    {
    for (ImgObject imgObject : imgObjects) {
    JSONObject jsonObject=new JSONObject();
    String str=imgObject.getImgPath();
    str=str.substring(str.indexOf(class2));
    str=str.substring(str.indexOf("\")+1);
    str=str.substring(0,str.indexOf("\"));
    System.out.println(str);
    if (!str2.equals(str)){
    str2=str;
    jsonObject.put("title",str2);
    jsonObject.put("img"," http://octoberimg.viphk.ngrok.org/SmartCloudAlbum_war_exploded/Cloud/DownloadImg?fileName="+imgObject.getImgId());
    jsonObject.put("imgID",imgObject.getImgId());
    jsonArray.add(jsonObject);
    }
    }

    }
    for (ImgObject imgObject : imgObjects) {
    JSONObject jsonObject=new JSONObject();
    String str=imgObject.getImgPath();
    //str=str.substring(str.indexOf("-")+1).substring(0,str.indexOf("\"));
    str=str.substring(str.indexOf(class2));
    str=str.substring(0,str.indexOf("\"));
    System.out.println(str);
    if (!str2.equals(str)){
    str2=str;
    jsonObject.put("title",str2);
    jsonObject.put("img"," http://octoberimg.viphk.ngrok.org/SmartCloudAlbum_war_exploded/Cloud/DownloadImg?fileName="+imgObject.getImgId());
    jsonObject.put("imgID",imgObject.getImgId());
    jsonArray.add(jsonObject);
    }
    }
    return jsonArray.toJSONString();
    }
    }
  • 相关阅读:
    Min_25筛
    POJ-1068 Parencodings---模拟括号的配对
    POJ-3295 Tautology---栈+表达式求值
    POJ-2586 Y2K Accounting Bug贪心,区间盈利
    POJ-1328 Radar Installation--区间选点问题(贪心)
    POJ-2965 The Pilots Brothers' refrigerator---思维题
    POJ-1753 Flip Game---二进制枚举子集
    南阳OJ-2-括号配对问题---栈的应用
    hdu-1082 Matrix Chain Multiplication---栈的运用
    hdu-1237 简单计算器---中缀表达式转后缀表达式
  • 原文地址:https://www.cnblogs.com/buxiang-Christina/p/14909549.html
Copyright © 2020-2023  润新知