DataPower API 게이트웨이만 해당됨

message 오브젝트에서 첨부 조작

message 오브젝트는 메시지 첨부를 조작하기 위한 API및 특성을 제공합니다.

어셈블리에 구문 분석 정책이 포함된 경우, 멀티파트 메시지의 요청 또는 응답에 있는 첨부 파일을 조작하여 클라이언트에 다시 전송할 수 있습니다. 기본적으로 응답은 멀티파트 형식으로 클라이언트에 전송됩니다.
제한 사항: 기존 첨부 파일이 없는 요청이나 응답에는 첨부 파일을 추가할 수 없습니다.
또는 context.message.attachments 를 선택 취소하여 첨부 파일을 버리고 클라이언트에 message.body 만 보낼 수 있습니다.
참고: 어셈블리에 구문 분석 정책이 포함되어 있지 않으면 다음 처리 규칙이 적용됩니다.
  • message.body 변수가 변경되지 않은 다중 파트 요청의 경우 호출 정책은 첨부를 보존하고 서버에 전달합니다.
  • message.body 변수가 변경되지 않은 다중 파트 요청 또는 응답의 경우, 결과 API 조치는 첨부를 최종 응답으로 전달합니다.
  • message.body 변수가 변경되면 첨부 파일을 버립니다.

첨부 파일 검색

GatewayScript 예제
색인 위치별로 첨부를 검색합니다.
context.message.attachments[1]
Content-Id 헤더에서 pic1 의 값을 검색하여 첨부 파일을 검색하십시오.
context.message.attachments['cid:pic1']
Content-Location 헤더에서 uri1 의 값을 검색하여 첨부 파일을 검색하십시오.
context.message.attachments['uri1']

메시지에 첨부 파일 추가

GatewayScript 예
var headers = JSON.parse ( '{ "Content-Type": "text/xml; charset=utf-8", "Content-Id": "<data>" }' );
context.message.attachments.append(headers, 'Hello world.');

배열에서 첨부 파일 수 검색

for (var i = 0; i < context.message.attachments.count; i++) {
  context.message.attachments[i].header.set('X-Foo', 'bar');
}

메시지에서 첨부 제거

GatewayScript 예제
색인 위치별로 첨부를 제거하십시오.
context.message.attachments.remove(1)
Content-Id 헤더에서 pic1 의 값을 검색하여 첨부 파일을 제거하십시오.
context.message.attachments.remove('cid:pic1')
Content-Location 헤더에서 uri1 의 값을 검색하여 첨부 파일을 제거하십시오.
context.message.attachments.remove('uri1')

첨부의 본문 읽기, 액세스 및 조작

GatewayScript 예제
첨부 파일의 페이로드를 2진으로 읽고 컨텐츠를 Buffer, Buffers, JSON또는 XML NodeList 오브젝트로 리턴하려면 다음을 수행하십시오.
context.message.attachments[0].body.readAsBuffer(function(errorObject,bufferObject){})
context.message.attachments[0].body.readAsBuffers(function(errorObject,buffersObject){})
context.message.attachments[0].body.readAsJSON(function(errorObject,jsonObject){})
context.message.attachments[0].body.readAsXML(function(errorObject,nodeList){})
첨부의 현재 페이로드에 Hello world 컨텐츠를 쓰려면 다음을 수행하십시오.
message.attachments[0].body.write("Hello world")

첨부 파일의 헤더 조작

GatewayScript 예제
전체 첨부 헤더의 값을 검색하려면 다음을 수행하십시오.
context.message.attachments[0].headers
첨부의 이름 지정된 헤더 값을 검색하려면 다음을 수행하십시오.
context.message.attachments[0].header.get();
첨부 파일의 현재 Content-Type 헤더를 삭제합니다.
context.message.attachments[0].header.remove('Content-Type');
첨부의 이름 지정된 헤더 값을 설정할 수 있습니다. 헤더를 병합하거나 병합하지 않을 수 있습니다. 다음 코드를 예로 들어 보겠습니다.
context.message.attachments[0].header.set('MyCookie', ['cookie1', 'cookie2']);
값 유형이 배열인 경우, MyCookie 헤더는 병합되지 않으며 HTTP 헤더에 다른 항목과 함께 존재합니다.
MyCookie: cookie1
MyCookie: cookie2