ADD JobService and UploadService
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.ddf.vodsystem.controllers;
|
||||
|
||||
import com.ddf.vodsystem.services.UploadService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
public class UploadController {
|
||||
|
||||
private final UploadService uploadService;
|
||||
|
||||
@Autowired
|
||||
public UploadController(UploadService uploadService) {
|
||||
this.uploadService = uploadService;
|
||||
}
|
||||
|
||||
@PostMapping("/upload")
|
||||
public ResponseEntity<String> uploadVideo(@RequestParam("file") MultipartFile file) {
|
||||
String uuid = uploadService.upload(file);
|
||||
|
||||
return new ResponseEntity<>(uuid, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.ddf.vodsystem.controllers;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
@RestController
|
||||
public class vodController {
|
||||
|
||||
private static final String UPLOAD_DIR = "videos/";
|
||||
|
||||
@PostMapping("/upload")
|
||||
public ResponseEntity<String> uploadVideo(@RequestParam("file") MultipartFile file) {
|
||||
try {
|
||||
File uploadDir = new File(UPLOAD_DIR);
|
||||
|
||||
if (!uploadDir.exists()) {
|
||||
uploadDir.mkdirs();
|
||||
}
|
||||
|
||||
Path filePath = Paths.get(UPLOAD_DIR, file.getOriginalFilename());
|
||||
Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
return ResponseEntity.ok("Uploaded: " + file.getOriginalFilename());
|
||||
} catch (IOException e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body("Upload failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user