-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from yanyanho/main
delete the ipfs service
- Loading branch information
Showing
2 changed files
with
83 additions
and
83 deletions.
There are no files selected for viewing
130 changes: 65 additions & 65 deletions
130
src/main/java/com/dl/officialsite/file/FileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
package com.dl.officialsite.file; | ||
|
||
import cn.hutool.core.io.IoUtil; | ||
import com.dl.officialsite.common.base.BaseResponse; | ||
import com.dl.officialsite.common.enums.CodeEnums; | ||
import com.dl.officialsite.common.exception.BizException; | ||
import com.dl.officialsite.ipfs.IPFSService; | ||
import lombok.Data; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* @ClassName FileController | ||
* @Author jackchen | ||
* @Date 2023/10/16 17:07 | ||
* @Description 文件上传 | ||
**/ | ||
@RestController | ||
@RequestMapping("/file") | ||
@Data | ||
@Slf4j | ||
public class FileController { | ||
|
||
private final IPFSService ipfsService; | ||
|
||
/** | ||
* 文件上传 | ||
*/ | ||
@PostMapping("/upload") | ||
public BaseResponse upload(@RequestParam("file") MultipartFile file, | ||
@RequestParam String address) { | ||
try { | ||
String hash = ipfsService.upload(file.getBytes()); | ||
return BaseResponse.successWithData(hash); | ||
} catch (IOException e) { | ||
log.error("文件上传失败{}", file.getName()); | ||
throw new BizException(CodeEnums.FAIL_UPLOAD_FAIL.getCode(), | ||
CodeEnums.FAIL_UPLOAD_FAIL.getMsg()); | ||
} | ||
} | ||
|
||
/** | ||
* 文件下载 | ||
*/ | ||
@GetMapping("/download") | ||
public void download(@RequestParam String fileHash, | ||
@RequestParam String address, HttpServletResponse response) | ||
throws IOException { | ||
InputStream inputStream = null; | ||
try { | ||
inputStream = ipfsService.downloadStream(fileHash); | ||
} catch (IOException e) { | ||
log.error("文件下载失败{}", fileHash); | ||
throw new BizException(CodeEnums.FAIL_DOWNLOAD_FAIL.getCode(), | ||
CodeEnums.FAIL_DOWNLOAD_FAIL.getMsg()); | ||
} | ||
response.setContentType("application/octet-stream"); | ||
IoUtil.copy(inputStream, response.getOutputStream()); | ||
} | ||
} | ||
//package com.dl.officialsite.file; | ||
// | ||
//import cn.hutool.core.io.IoUtil; | ||
//import com.dl.officialsite.common.base.BaseResponse; | ||
//import com.dl.officialsite.common.enums.CodeEnums; | ||
//import com.dl.officialsite.common.exception.BizException; | ||
//import com.dl.officialsite.ipfs.IPFSService; | ||
//import lombok.Data; | ||
//import lombok.extern.slf4j.Slf4j; | ||
//import org.springframework.web.bind.annotation.*; | ||
//import org.springframework.web.multipart.MultipartFile; | ||
// | ||
//import javax.servlet.http.HttpServletResponse; | ||
//import java.io.IOException; | ||
//import java.io.InputStream; | ||
// | ||
///** | ||
// * @ClassName FileController | ||
// * @Author jackchen | ||
// * @Date 2023/10/16 17:07 | ||
// * @Description 文件上传 | ||
// **/ | ||
//@RestController | ||
//@RequestMapping("/file") | ||
//@Data | ||
//@Slf4j | ||
//public class FileController { | ||
// | ||
// private final IPFSService ipfsService; | ||
// | ||
// /** | ||
// * 文件上传 | ||
// */ | ||
// @PostMapping("/upload") | ||
// public BaseResponse upload(@RequestParam("file") MultipartFile file, | ||
// @RequestParam String address) { | ||
// try { | ||
// String hash = ipfsService.upload(file.getBytes()); | ||
// return BaseResponse.successWithData(hash); | ||
// } catch (IOException e) { | ||
// log.error("文件上传失败{}", file.getName()); | ||
// throw new BizException(CodeEnums.FAIL_UPLOAD_FAIL.getCode(), | ||
// CodeEnums.FAIL_UPLOAD_FAIL.getMsg()); | ||
// } | ||
// } | ||
// | ||
// /** | ||
// * 文件下载 | ||
// */ | ||
// @GetMapping("/download") | ||
// public void download(@RequestParam String fileHash, | ||
// @RequestParam String address, HttpServletResponse response) | ||
// throws IOException { | ||
// InputStream inputStream = null; | ||
// try { | ||
// inputStream = ipfsService.downloadStream(fileHash); | ||
// } catch (IOException e) { | ||
// log.error("文件下载失败{}", fileHash); | ||
// throw new BizException(CodeEnums.FAIL_DOWNLOAD_FAIL.getCode(), | ||
// CodeEnums.FAIL_DOWNLOAD_FAIL.getMsg()); | ||
// } | ||
// response.setContentType("application/octet-stream"); | ||
// IoUtil.copy(inputStream, response.getOutputStream()); | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters