Saving MAFileModel to filesystem

Damien Cassou damien.cassou at laposte.net
Tue Sep 26 13:22:34 MEST 2006


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



More information about the SmallWiki mailing list