zoukankan      html  css  js  c++  java
  • 5.2团队冲刺05

    今天做了文件下载

    下面是代码,下载还是根据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();
    }
    }
  • 相关阅读:
    MicroPython实例之TurnipBit开发板自动浇水实验
    MicropPython的学习,如何从0到1?
    MicroPython最全资料免费获取
    MicroPython技术及应用前景
    如何将AD原理图直接转为Orcad原理图
    USB音频声卡的时钟同步方式----同步、异步、自适应
    字符串指针数组长度
    关于传统模拟电话按键时间
    小米笔记本13.3寸 八代i5独显 记录
    小米笔记本Air 13.3 熄屏 大概率无法唤醒问题(已解决)
  • 原文地址:https://www.cnblogs.com/L-L-ALICE/p/14910300.html
Copyright © 2011-2022 走看看