본문 바로가기

Spring Boot

[Springboot + Vimeo] vimeo 동영상 파일삭제 구현

반응형

1. 먼저 Vimeo 계정을 만들고 Vimeo Developer 웹 사이트에서 Vimeo API 액세스 토큰을 가져옵니다.

2. Spring Boot 프로젝트에서 다음 종속성을 pom.xml 파일에 추가합니다.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
  <groupId>org.glassfish.jersey.core</groupId>
  <artifactId>jersey-client</artifactId>
  <version>2.26</version>
</dependency>

 

3. 비디오 삭제를 처리할 컨트롤러 클래스를 만듭니다. 이 클래스에서 Jersey의 Client API를 사용하여 Vimeo에서 특정 비디오를 삭제하는 방법을 정의합니다.

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class VideoController {
  
  @DeleteMapping("/delete/{videoId}")
  public void deleteVideo(@PathVariable("videoId") String videoId) {
    try {
      // Create a Vimeo client
      Client client = ClientBuilder.newClient();
      
      // Endpoint for deleting a specific video
      String videoEndpoint = "https://api.vimeo.com/videos/" + videoId;
      
      // Request headers
      String accessToken = "your_access_token";
      
      // Make a DELETE request to the video endpoint
      Response response = client
        .target(videoEndpoint)
        .request()
        .header("Authorization", "Bearer " + accessToken)
        .delete();
      
      // Check the response status
      if (response.getStatus() == 204) {
        System.out.println("Video deleted successfully.");
      } else {
        System.out.println("Video deletion failed.");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
반응형