On Fri, Jul 11, 2008 at 4:14 AM, Julien Phalip <[EMAIL PROTECTED]> wrote:
> Not sure if we're talking about the same thing here. What I ask is if
> it'd be a good idea to have a generic method for UploadedFile which
> lets copy/move the file to where ever you want. These method would
> have to be overriden by InMemoryUploadedFile or TemporaryUploadedFile,
> but would allow to have something as simple as:
>
> uploaded_file.move_to("some/path/")
>
> I agree with Ivan that it is a common operation and that having it
> core in the API would avoid some boilerplate code, and as result that
> would prevent potential mistakes by the developer.
Okay, two things:
First, Django does now contain the code you're asking for, at
django.core.files.move, which performs memory-friendly file moves in a
platform-independent way.
Second, file uploads are really just half of the equation. I'm
currently working on a patch for file storage, which will handle the
other side of it. Right now, yes, the focus has been on getting the
file uploaded in a sane manner, but once the other half lands (I'm
nearly done with a new patch for it), it'll be dead simple to save
uploaded files without wasting memory *and* without caring what
backend you're using.
Here's an example of what the API would probably look like:
from django.core.files.storage import default_storage
default_storage.save('path/to/files/%s' % uploaded_file.name, uploaded_file)
That API may change slightly before it gets committed, but behind the
scenes, that would use shutils or os.rename, or chunk directly to S3
or whatever is most efficient for what you're trying to do.
-Gul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---