CSP store/view global-data as 'img src'/picture

188 views
Skip to first unread message

Christian Ditters

unread,
Feb 24, 2006, 12:33:41 PM2/24/06
to intersystems...@info2.kinich.com
hi, i want to store a f ile (eg .tif/.jpg) as a global and use this data to
display on a website.
storing data (object script) to global '^test' seems to work with this code:

<html>
<form action="test.csp" enctype="multipart/form-data" method=post>
<input name="FileStream" type="file" size="50"></td></tr>
<input type="submit" name="btn" value="speichern"></td></tr>
</form>
<script language="Cache" runat="server">
i $d(%request.MimeData("FileStream",1)) d ;
. s name=%request.MimeData("FileStream",1).FileName
. s size=%request.MimeData("FileStream",1).Size
. s section=%request.MimeData("FileStream",1).MimeSection
. s type=%request.MimeData("FileStream",1).%ClassName(1)
. s content=%request.MimeData("FileStream",1).ContentType
. f i=1:1:((size\80)+1) d ;
.. s ^test("stream",i)=%request.MimeData("FileStream",1).Read(80)
</script>
</html>

but how can i use this 'global-data' to display as "<img src="...?
any idea?

thanks
christian

Denver

unread,
Feb 24, 2006, 12:58:45 PM2/24/06
to intersystems...@info2.kinich.com
Christian Ditters wrote:
> How can I display a %GlobalBinaryStream as <img src="..."/>?

See example below for other content type.
Of course you want to change the content type to "image/jpeg" or whatever is appropriate.
You need to open and use the correct %GlobalBinaryStream rather than %FileBinaryStream.
You can make one CSP that serves all images.
<img src="imageserve.csp?filename=myImage1.jpg"/>

If you have any trouble with the modifications, just ask.
If you would like to code this as a regular CSP, Nuno provided an example last year that I can get for you which you can modify for %Streams.
Remember to share your code by posting it here when you are done.
Hopefully we'll end up with generalized code someday.
There is nothing about %CSP.StreamServer code that is specific to just one MIME type.

Q. How do I display a file as a content type other than text/html as a CSP?

A. [Frank Schob, 2005-Jun-24@07:59:47Z, <42bbb...@info2.kinich.com>]
/// Display a PDF file
/// Expects a valid pdf file name specifed as parameter 'filename'
Class CWS.CSP.PDFViewer Extends %CSP.StreamServer [ ProcedureBlock ]
{
ClassMethod OnPreHTTP() As %Boolean
{
s ret=0
s FileName=$G(%request.Data("filename",1))
if FileName'="" {
if ##class(%File).Exists(FileName) {
s stream=##class(%FileBinaryStream).%New()
d stream.LinkToFile(FileName)
s %response.ContentType="application/pdf"
d %response.SetHeader("Content-disposition","inline; filename=my.pdf")
s %response.Expires=-1
s %response.ContentLength=stream.Size
s ret=$$$OK
}
}
q ret
}
ClassMethod OnPage() As %Status
{
s FileName=$G(%request.Data("filename",1))
s stream=##class(%FileBinaryStream).%New()
s stream.Filename=FileName
d stream.OutputToDevice()
q $$$OK
}
}

Enrico Parisi

unread,
Feb 24, 2006, 1:35:26 PM2/24/06
to intersystems...@info2.kinich.com
Hi Denver,

why are you extending %CSP.StreamServer when you override what it
implements? In that case....just extend %CSP.Page, or I'm missing something?
Ciao
Enrico

Denver

unread,
Feb 24, 2006, 1:51:36 PM2/24/06
to intersystems...@info2.kinich.com
Enrico Parisi wrote:
> why are you extending %CSP.StreamServer?
I'm not.

> In that case....just extend %CSP.Page, or I'm missing something?

Yes, it's not my code. I don't use it.

A better question is why any method needs to be overridden.
I am suggesting that using FileClassify() and getting back to a generalized implementation would be a good idea.

Nuno Canas

unread,
Feb 24, 2006, 3:28:24 PM2/24/06
to intersystems...@info2.kinich.com
Denver wrote:
<snip>

> If you have any trouble with the modifications, just ask.
> If you would like to code this as a regular CSP, Nuno provided an
</snip>

Here you have a very basic example:


<File LoadPicture.csp>

<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../Style.css" rel="stylesheet" type="text/css">
<TITLE> Add Picture </TITLE>

</HEAD>
<BODY>
<form action="" enctype="multipart/form-data" method=post>
<table>
<tr>
<td>Enter a file to upload:</td>
<td><input name="FileStream" size=30 type="file"></td>
</tr>
<tr>
<td colspan=2 align="center">
<input type="submit" value="Upload file">
</td>
</tr>
</table>

<p>
</form>
<script language="cache" runat="server">
w $$$cspJavaScriptStart,!
set xid=%request.Get("OBJID")
set xclass=%request.Get("CLASSE")
set xfield=%request.Get("FIELD")
//w "alert('OBJ:"_%request.Get("OBJID")_"');",!
w $$$cspJavaScriptEnd,!
</script>
<csp:IF CONDITION=($data(%request.MimeData("FileStream",1)))>
<hr>
<table width="100%">
<tr><td>Submitted
filename:</td><td><b>#(%request.MimeData("FileStream",1).FileName)#</b></td></tr>
<tr><td>Size of
file:</td><td><b>#(%request.MimeData("FileStream",1).Size)#
bytes</b></td></tr>
<tr><td>Mime
Section:</td><td><b>#(%request.MimeData("FileStream",1).MimeSection)#</b></td></tr>
<tr><td>Type of
stream:</td><td><b>#(%request.MimeData("FileStream",1).%ClassName(1))#</b></td></tr>
<tr><td>Content
Type:</td><td><b>#(%request.MimeData("FileStream",1).ContentType)#</b></td></tr>
</table>
<hr>
<script language=Cache runat=server>
w $$$cspJavaScriptStart,!
Set @("o = ##class("_xclass_").%OpenId("""_%request.Get("OBJID")_""")")
; copy the file into Memo
s $zobjproperty(o,xfield)=%request.MimeData("FileStream",1)
Set @("ss = o."_xfield_".SaveStream()")
; save the object and close it
set sc=o.%Save()

Do o.%Close()
kill o
; close the file
w "loc=opener.document.location;",!
w "opener.document.location=loc;",!
w "self.close();",!
w $$$cspJavaScriptEnd,!
</script>
</ul>
</csp:IF>
</BODY>
</HTML>

</File LoadPicture.csp>

<File Picture.csp>

<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../Style.css" rel="stylesheet" type="text/css">
<TITLE> View Picture </TITLE>
</HEAD>
<BODY>
<csp:object name="objForm" classname="User.Foto"
OBJID=#(%request.Get("OBJID"))#>
<form name="form" cspbind="objForm" cspjs="All" onsubmit='return
form_validate();'>
<center>
<img name="Foto" cspbind="Foto" width="180" height="200"
onDblclick="#server(..PutPicture('User.Foto','Foto','#(%request.Get("OBJID"))#'))#">
</center>
</form>
</BODY>
</HTML>

<script language="Cache" method="PutPicture"
arguments="classname:%String,fieldname:%String,xobj:%String"
returntype="%Boolean">
if (xobj'="") {
w
"window.open('./LoadPicture.csp?CLASSE="_classname_"&FIELD="_fieldname_"&OBJID="_xobj');",!
}
quit $$$OK
</script>

</File Picture.csp>

Frank Schob

unread,
Feb 27, 2006, 3:21:55 AM2/27/06
to intersystems...@info2.kinich.com
Enrico Parisi wrote:
> Hi Denver,
>
> why are you extending %CSP.StreamServer when you override what it
> implements? In that case....just extend %CSP.Page, or I'm missing
> something?
Ok, "%CSP.Page" would fit in this case. The reason is that the class
below is a simplification (for posting) of a more complex class.

Frank

Reply all
Reply to author
Forward
Message has been deleted
0 new messages