Cool. Thanks, Damien.
One quick question. How would I remove the file's data from the
contents variable so it does not hang around the image? Would it be
good enough to just set the contents variable to nil once the file is
saved to the directory?
Thanks,
Chad
On 9/26/06, Damien Cassou <damien.cassou(a)laposte.net> wrote:
Chad Nantais a écrit :
What's the best way to have an
MAFileDescription upload save the
MAFileModel contents to the filesystem instead of the Squeak image.
I'm talking about image mimetypes in this case, which I will be
serving with a seperate Komanche instance and I don't want them
bloating my Squeak image.
I just did a command this morning that allows the user to upload a file
and place it to a given directory.
There is some odd things but it works.
PRCommand subclass: #PRUpload
instanceVariableNames: 'file destination directory'
classVariableNames: ''
poolDictionaries: ''
category: 'Pier-Model-Command'
PRUpload>>destination
^ destination
PRUpload>>destination: aString
destination := aString
PRUpload>>file
^ file
PRUpload>>file: aMAFileModel
file := aMAFileModel
PRUpload>>doValidate
super doValidate.
(FileDirectory default directoryExists: self destination)
ifFalse: [MAError raiseSignal: 'Destination does not exist'].
directory := (FileDirectory default directoryNamed: self destination).
(directory fileExists: self file filename)
ifTrue: [MAError raiseSignal: 'A file with the same name already
exist. Please rename the file!'].
self writeFile.
PRUpload>>writeFile
|stream |
stream := self file contents readStream.
(directory putFile: stream named: self file filename)
ifFalse: [MAError raiseSignal: 'An error occurred while trying to
create a file with the given name in the destination folder!'].
PRUpload class
instanceVariableNames: ''
PRUpload class>>descriptionDestination
^ (MAStringDescription auto: #destination label: 'Destination'
priority: 200 default: 'resources')
beRequired;
yourself
PRUpload class>>descriptionFile
^ (MAFileDescription auto: #file label: 'File' priority: 100)
beRequired;
yourself
PRUpload class>>isAbstract
^ false
PRUpload class>>label
^ 'Send a file'
--
Damien Cassou
_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki