You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/core/src/decorators/attachment/Attachment.ts
+15
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,8 @@ import {
11
11
ValidateNested,
12
12
}from'class-validator'
13
13
14
+
import{AriesFrameworkError}from'../../error'
15
+
import{JsonEncoder}from'../../utils/JsonEncoder'
14
16
import{uuid}from'../../utils/uuid'
15
17
16
18
exportinterfaceAttachmentOptions{
@@ -45,6 +47,19 @@ export class AttachmentData {
45
47
}
46
48
}
47
49
50
+
/*
51
+
* Helper function returning JSON representation of attachment data (if present). Tries to obtain the data from .base64 or .json, throws an error otherwise
52
+
*/
53
+
publicgetDataAsJson<T>(): T{
54
+
if(typeofthis.base64==='string'){
55
+
returnJsonEncoder.fromBase64(this.base64)asT
56
+
}elseif(this.json){
57
+
returnthis.jsonasT
58
+
}else{
59
+
thrownewAriesFrameworkError('No attachment data found in `json` or `base64` data fields.')
60
+
}
61
+
}
62
+
48
63
/**
49
64
* Base64-encoded data, when representing arbitrary content inline instead of via links. Optional.
0 commit comments