웹 액션 활용
    • PDF

    웹 액션 활용

    • PDF

    Article Summary

    Classic/VPC 환경에서 이용 가능합니다 .

    웹 액션에 대한 이해와 활용에 도움을 줄 수 있는 다양한 포맷별 예제, HTTP redirect 예제, 헤더 쿠키 설정 예제, 이미지 응답 예제를 소개합니다. 예제 코드는 다음과 같습니다.

    • json 형식의 예제

      • type을 json으로 호출하는 경우
        function main(params) {
               return {"key" : "value"}
         }
        
      • type을 http로 호출하는 경우
        function main(params) {
                return {
                    statusCode: 200,
                    headers: { 'Content-Type': 'application/json' },
                    body: {"key":"value"}
                };
        }
        
    • html 형식의 예제

      • type을 html로 호출하는 경우
        function main(params) {
              return {"html":"<html><body><h3>hello</h3></body></html>"}
        }
        
      • type을 http로 호출하는 경우
        function main() {
              return {
                headers: {
                  'Content-Type': 'text/html'
                },
                statusCode: 200,
                body: '<html><body><h3>hello</h3></body></html>' }
        }
        
    • text 형식의 예제

      • type을 text로 호출하는 경우
        function main(params) {
              return {"text":"hello"}   
        }
        
      • type을 http로 호출하는 경우
        function main() {
              return {
                headers: {
                  'Content-Type': 'text/plain'
                },
                statusCode: 200,
                body: 'hello' }
        }
        
    • HTTP redirect 예제

      function main() {
        return {
          headers: { location: 'https://www.ncloud.com' },
          statusCode: 302
        }
      }
      
    • 헤더 쿠키 설정 예제

      function main() {
        return {
          headers: {
            'Set-Cookie': 'UserID=Jane; Max-Age=3600; Version=',
            'Content-Type': 'text/html'
          },
          statusCode: 200,
          body: '<html><body><h3>hello</h3></body></html>' }
      }
      
      function main() {
        return {
          headers: {
            'Set-Cookie': [
              'UserID=Jane; Max-Age=3600; Version=',
              'SessionID=asdfgh123456; Path = /'
            ],
            'Content-Type': 'text/html'
          },
          statusCode: 200,
          body: '<html><body><h3>hello</h3></body></html>' }
      }
      
    • 이미지 응답 예제: 콘텐츠 타입을 image/png로 설정하여 base64 문자열을 통해 이미지를 반환

      function main() {
          let png = <base 64 encoded string>
          return { headers: { 'Content-Type': 'image/png' },
                   statusCode: 200,
                   body: png };
      }
      
      주의

      액션이 반환할 수 있는 최대 응답 크기가 있기 때문에 최대 크기를 초과하는 응답값 반환 시도 시 액션 실행 결과를 실패로 처리됩니다. 따라서 위 예제의 이미지와 같은 객체 파일을 반환하려는 경우 최대 응답 크기에 주의하되 최대 크기를 초과하는 경우 액션 코드로 반환하지 않고 다른 저장소를 이용해 주십시오. 최대 응답 크기에 대한 사양은 Cloud Functions 사용 준비를 참고해 주십시오.


    이 문서가 도움이 되었습니까?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.