-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathFile.cls.xml
137 lines (125 loc) · 4.01 KB
/
File.cls.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Class name="Form.File">
<Super>%Persistent</Super>
<TimeCreated>64090,76829.939948</TimeCreated>
<Property name="name">
<Description>
File name as supplied by user</Description>
<Type>%String</Type>
<Required>1</Required>
<Parameter name="MAXLEN" value="1000"/>
<Parameter name="MINLEN" value="1"/>
</Property>
<Property name="dir">
<Description>
Directory, where file is stored</Description>
<Type>%String</Type>
<Required>1</Required>
<Parameter name="MAXLEN" value="1000"/>
<Parameter name="MINLEN" value="1"/>
</Property>
<Property name="realName">
<Description>
Full path to where file is stored</Description>
<Type>%String</Type>
<SqlComputeCode>set {*} = {dir} _ {attachmentHASH}</SqlComputeCode>
<SqlComputed>1</SqlComputed>
<SqlComputeOnChange>attachmentHASH,dir</SqlComputeOnChange>
<Parameter name="MAXLEN" value="1000"/>
<Parameter name="MINLEN" value="1"/>
</Property>
<Property name="description">
<Description>
Description</Description>
<Type>%String</Type>
<Parameter name="MAXLEN" value="500"/>
</Property>
<Property name="attachmentHASH">
<Description>
Attachmentt SHA Hash in Base64</Description>
<Type>%String</Type>
</Property>
<Property name="stream">
<Description>
The file itself (data is stored on disk, it's just a link)</Description>
<Type>%FileBinaryStream</Type>
</Property>
<Method name="%OnNew">
<Description><![CDATA[
This callback method is invoked by the <METHOD>%New</METHOD> method to
provide notification that a new instance of an object is being created.
<P>If this method returns an error then the object will not be created.
<p>It is passed the arguments provided in the %New call.
When customizing this method, override the arguments with whatever variables and types you expect to receive from %New().
For example, if you're going to call %New, passing 2 arguments, %OnNew's signature could be:
<p>Method %OnNew(dob as %Date = "", name as %Name = "") as %Status
If instead of returning a %Status code this returns an oref and this oref is a subclass of the current
class then this oref will be the one returned to the caller of %New method.]]></Description>
<FormalSpec>name:%String="",dir:%String="",description:%String="",stream:%Stream.Object=##class(%FileBinaryStream).%New()</FormalSpec>
<Private>1</Private>
<ReturnType>%Status</ReturnType>
<ServerOnly>1</ServerOnly>
<Implementation><![CDATA[
#dim sc As %Status = $$$OK
set ..name = name
set ..description = description
set ..attachmentHASH = $system.Encryption.Base64Encode($zcvt($system.Encryption.SHAHashStream(512, stream, .sc),"O","UTF8"), 1)
return:$$$ISERR(sc) sc
set ..stream.Filename = dir _ ..attachmentHASH
set sc = ..stream.CopyFromAndSave(stream)
quit sc
]]></Implementation>
</Method>
<Method name="serve">
<Description>
Serve file in web context</Description>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
#dim sc As %Status = $$$OK
#dim %response As %CSP.Response
kill %request.Data
set %request.Data("STREAMOID",1)= ##class(%CSP.StreamServer).Encrypt(..stream.%Oid())
if ##class(%CSP.StreamServer).OnPreHTTP() {
set %response.Headers("Content-Disposition")="attachment; filename*=UTF-8''"_##class(%CSP.Page).EscapeURL(..name,"UTF8")
set st = ##class(%CSP.StreamServer).OnPage()
}
quit sc
]]></Implementation>
</Method>
<Storage name="Default">
<Type>%Library.CacheStorage</Type>
<DataLocation>^Form.FileD</DataLocation>
<DefaultData>FileDefaultData</DefaultData>
<IdLocation>^Form.FileD</IdLocation>
<IndexLocation>^Form.FileI</IndexLocation>
<StreamLocation>^Form.FileS</StreamLocation>
<Data name="FileDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>name</Value>
</Value>
<Value name="3">
<Value>description</Value>
</Value>
<Value name="4">
<Value>attachmentGUID</Value>
</Value>
<Value name="5">
<Value>attachmentHASH</Value>
</Value>
<Value name="6">
<Value>stream</Value>
</Value>
<Value name="7">
<Value>realName</Value>
</Value>
<Value name="8">
<Value>dir</Value>
</Value>
</Data>
</Storage>
</Class>
</Export>