logo       
Google Custom Search
    AddThis Social Bookmark Button

Re: Is it possible to know uploaded file name ?: msg#00116

Subject: Re: Is it possible to know uploaded file name ?
Dmitry Dorofeev wrote:

Hi All,

When i use file upload entry like this:

html fileUploadWithCallback: [:f | ....]

I get file content of the uploaded file (String) in the f.
Is there a way to know original filename?

Thanks.
-Dmitry.


Hmm...when I use fileUploadWithCallback: I get an instance of WAFile in the callback. I simply send it #fileName to get the name. You have to make sure to:

html attributeAt: 'enctype' put: 'multipart/form-data'.

right before you send form:.  Attached is a component that I use a lot.

David

'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 20 March 2005 
at 11:46:15 am'!
WAComponent subclass: #PageUploader
        instanceVariableNames: 'lastFilename directory'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'SC-Components'!

!PageUploader methodsFor: 'accessing' stamp: 'cds 4/3/2004 23:57'!
directory
        ^directory! !

!PageUploader methodsFor: 'accessing' stamp: 'cds 4/3/2004 23:57'!
directory: anObject
        directory := anObject! !


!PageUploader methodsFor: 'actions' stamp: 'cds 4/4/2004 00:02'!
fileSent: file 
        | f |
        file isNil | file isString
                ifTrue: [^ nil].
        lastFilename _ file fileName.
        f _ self directory
                                forceNewFileNamed: (self fixName: file 
fileName).
        [f nextPutAll: file contents]
                ensure: [f close]! !

!PageUploader methodsFor: 'actions' stamp: 'cds 4/8/2004 16:03'!
fixName: fileName 
        fileName ifNil: [^nil].
        ^ (fileName findTokens: '\/') last! !

!PageUploader methodsFor: 'actions' stamp: 'cds 4/2/2004 17:56'!
lastFilenameOrEmptyString
        ^lastFilename ifNil: ['']! !


!PageUploader methodsFor: 'rendering' stamp: 'cds 4/3/2004 23:52'!
renderContentOn: html 
        html attributeAt: 'enctype' put: 'multipart/form-data'.
        html
                form: [html
                                fileUploadWithValue: self 
lastFilenameOrEmptyString
                                callback: [:f | self fileSent: f].
                        html submitButtonWithText: 'Send file']! !
_______________________________________________
Seaside mailing list
Seaside@xxxxxxxxxxxxxxxxxxxxxxxxxx
http://lists.squeakfoundation.org/listinfo/seaside

Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>