Re: Help with error uploading files

2012-11-08 Thread Carlos Aguilar
The screenshot is captured with chrome extension, then, capture all page
and save to png.

The problem is caused by s3_folder_storages. I am replacing the
DEFAULT_FILE_STORAGE bY s3boto storage.

I think as field is ImageField png or jpg are valid images

Best Regards


On Thu, Nov 8, 2012 at 1:21 PM, Dennis Lee Bieber wrote:

> On Wed, 7 Nov 2012 21:10:06 -0800 (PST), Carlos Aguilar
>  declaimed the following in
> gmane.comp.python.django.user:
>
> > Hello,
> >
> > I am working in a project that requires you upload an image in a model.
> The
> > project was started by other developer.
> >
> > Today testing, without realize changes in the model I am receiving the
> > following error:
> >
> > 'cStringIO.StringO' object has no attribute 'size'
>
> Is that a cut? If it is, I suspect a typo...
>
> >
> > I not have idea what is causing the error, then I appreciate your help to
> > fix this.
> >
> > One screenshot of the error:
> >
> > <
> https://lh6.googleusercontent.com/-duPf2J5ejnI/UJs-gygXKgI/CDA/SmKl6Zk2sPM/s1600/waitress-error.png
> >
>
> What type of screen are you using... Even at "full view" my browser
> shows ant droppings... The text lines are TWO PIXELS tall!
>
> Not to mention you called it a PNG file, but that site is displaying a
> JPEG.
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Carlos Aguilar
Consultor Hardware y Software
DWD
http://www.dwdandsolutions.com
http://www.houseofsysadmin.com
Cel: +50378735118
USA: (301) 337-8541

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Help with error uploading files

2012-11-08 Thread Carlos Aguilar
Yesterday doing few test I note that the problem is causes by the following 
configs

DEFAULT_FILE_STORAGE = 'waitress.apps.venues.storage.CachedS3BotoStorage'
DEFAULT_S3_PATH = "media"

I test 2 file storages one is s3_folder_storages.s3.DefaultStorages.

I am using the same config in other project without problems.

I will appreciate your help

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/8waBUK8RcFYJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Help with error uploading files

2012-11-07 Thread Carlos Aguilar
Hello,

I am working in a project that requires you upload an image in a model. The 
project was started by other developer. 

Today testing, without realize changes in the model I am receiving the 
following error:

'cStringIO.StringO' object has no attribute 'size'

I not have idea what is causing the error, then I appreciate your help to 
fix this.

One screenshot of the error:



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/r9g4OfY4aygJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Libraries for generating URL of uploading files in Django

2012-06-01 Thread Kurtis Mullins
Check out django-storages (if you use off-site hosting like S3, Rackspace
Files, etc...). Then, just request the ImageField or FileField's .url()
method.

I think this may be the case for the bulit-in ImageField and FileField as
well (actually, I'm pretty sure it is) but I haven't used it in so long
that I can't remember if it takes the same formatting.

Good luck!

On Fri, Jun 1, 2012 at 3:45 AM, First Rock wrote:

> Need to develop a project for file uploading and generating
> its(files's) URL, which could be shared. Are there any particular
> libraries or simple means in Python,(Django) that would be handy and
> efficient.? ~ Newbie trying a Herculean Task~ Thanks in Advance :)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Libraries for generating URL of uploading files in Django

2012-06-01 Thread First Rock
Need to develop a project for file uploading and generating
its(files's) URL, which could be shared. Are there any particular
libraries or simple means in Python,(Django) that would be handy and
efficient.? ~ Newbie trying a Herculean Task~ Thanks in Advance :)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Confused about uploading files (Cannot force both insert and updating in model saving)

2011-06-06 Thread Roy Smith

> >    if form.is_valid():
> >             f = request.FILES['file']
> >             data_set = DataSet()
> >             data_set.save('foo', f)
>
> I suspect this is the problem: you create an empty instnce of DataSet
> and then call its save method. model.save has three optional arguments
> [1], in this case you call it with force_insert='foo', force_update=f.
>
> Both f and 'foo' evaluate to True, which is an obvious conflict.

Ah, yes, of course.  I was mixing up model.save() and
model.FileField.save().  Thanks for setting me straight.  What I
wanted was this:

if form.is_valid():
f = request.FILES['file']
data_set = DataSet(file=f)
data_set.save()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Confused about uploading files (Cannot force both insert and updating in model saving)

2011-06-06 Thread Michal Petrucha
On Sun, Jun 05, 2011 at 07:18:24PM -0700, Roy Smith wrote:
> I'm trying to figure out how to upload a file.  I've got a model that
> looks like:
> 
> class DataSet(models.Model):
> file = models.FileField(upload_to='data/%Y/%m/%d')
> 
> and my view method is:
> 
> def create_data_set(request):
> if request.method == 'POST':
>   form = DataSetForm(request.POST,
>request.FILES)
>   if form.is_valid():
> f = request.FILES['file']
> data_set = DataSet()
> data_set.save('foo', f)

I suspect this is the problem: you create an empty instnce of DataSet
and then call its save method. model.save has three optional arguments
[1], in this case you call it with force_insert='foo', force_update=f.

Both f and 'foo' evaluate to True, which is an obvious conflict.

Michal

[1] 
https://docs.djangoproject.com/en/1.3/ref/models/instances/#django.db.models.Model.save


signature.asc
Description: Digital signature


Re: Confused about uploading files (Cannot force both insert and updating in model saving)

2011-06-05 Thread Kenneth Gonsalves
On Sun, 2011-06-05 at 19:18 -0700, Roy Smith wrote:
> ctx = {'form': form}
> ctx.update(csrf(request)) 

indent these two lines
-- 
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://ilugcbe.techstud.org/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Confused about uploading files (Cannot force both insert and updating in model saving)

2011-06-05 Thread Roy Smith
I'm trying to figure out how to upload a file.  I've got a model that
looks like:

class DataSet(models.Model):
file = models.FileField(upload_to='data/%Y/%m/%d')

and my view method is:

def create_data_set(request):
if request.method == 'POST':
form = DataSetForm(request.POST,
   request.FILES)
if form.is_valid():
f = request.FILES['file']
data_set = DataSet()
data_set.save('foo', f)
return HttpResponseRedirect("/")
print "invalid"
else:
form = DataSetForm()
ctx = {'form': form}
ctx.update(csrf(request))
return render_to_response('chart/data_set.html', ctx)

with a form

class DataSetForm(forms.Form):
file = forms.FileField()

When I execute this, I get a form containing a file picker (so far, so
good), but when I submit the form I get a mysterious error (below).
What am I doing wrong?


Environment:


Request Method: POST
Request URL: http://localhost:8000/dataset/create

Django Version: 1.3
Python Version: 2.6.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'chart']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/Users/roy/lib/webchart/lib/python2.6/site-packages/Django-1.3-
py2.6.egg/django/core/handlers/base.py" in get_response
  111. response = callback(request,
*callback_args, **callback_kwargs)
File "/Users/roy/WebChart/chart/views.py" in create_data_set
  27. data_set.save('foo', f, False)
File "/Users/roy/lib/webchart/lib/python2.6/site-packages/Django-1.3-
py2.6.egg/django/db/models/base.py" in save
  459. raise ValueError("Cannot force both insert and
updating in model saving.")

Exception Type: ValueError at /dataset/create
Exception Value: Cannot force both insert and updating in model
saving.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Uploading files with FormPreview

2010-06-18 Thread Jacob Fenwick
Does FormPreview support uploading files?

I imagine I would need to override the templates to change the form enctype
and override the validation view so that it will check for request.FILES,
but is there a way to do this easily? Or will it just be an ugly, hacky mess
that's not worth embarking on?

Or is there an easier way I'm not seeing in the documentation?

Jacob

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



admin: uploading files problem

2009-11-28 Thread Heronman
Hello, all

I'm a newbie in django, and I have a problem with uploading files in
django admin
after submitting a form with FileField or ImageField, if a file is
bigger than ~100KB, my browser tell me "sending a request..." and then
nothing happens. and nothing happens on the server side
FILE_UPLOAD_MAX_MEMORY_SIZE and other file uploading settings are
default
permissions on /tmp directory is 0777 (anyway, that problem persists
even if django is running under root)

when using a file-upload forms in my own pages under django, all works
good, with any file size

what can I do to solve this problem?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: uploading files

2009-02-17 Thread Tonu Mikk

Karen Tracey wrote:
> On Tue, Feb 17, 2009 at 11:50 AM, Tonu Mikk  > wrote:
>
> Alex Gaynor wrote:
>
> > Uploaded files have a name attribute that contains their name.
> Yes, but how does one take advantage of that in this code?
>
>
> You simply use the name attribute of the UploadedFile instance you are 
> working with.  For example, if you wanted to rewrite the example you 
> cited earlier to use the original name of the uploaded file, it would be:
>
> def handle_uploaded_file(f):
>destination = open(f.name , 'wb+')
>for chunk in f.chunks():
>destination.write(chunk)
>destination.close()
Karen, thanks for this.  I don't quite see though how I can add the path 
info into this construct.  But here again, lack of Python experience is 
showing.

Tonu

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: uploading files

2009-02-17 Thread Karen Tracey
On Tue, Feb 17, 2009 at 11:50 AM, Tonu Mikk  wrote:

> Alex Gaynor wrote:
>
> Uploaded files have a name attribute that contains their name.
> Yes, but how does one take advantage of that in this code?
>

You simply use the name attribute of the UploadedFile instance you are
working with.  For example, if you wanted to rewrite the example you cited
earlier to use the original name of the uploaded file, it would be:

def handle_uploaded_file(f):
   destination = open(f.name, 'wb+')
   for chunk in f.chunks():
   destination.write(chunk)
   destination.close()

(If this wasn't obvious from the doc, you may need to do a bit more learning
of Python before you are comfortable working with Django.)

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: uploading files

2009-02-17 Thread Tonu Mikk

Alex Gaynor wrote:
>
>
> On Tue, Feb 17, 2009 at 11:18 AM, Tonu Mikk <tm...@umn.edu 
> <mailto:tm...@umn.edu>> wrote:
>
>
> Hi Django community,
>
>     I have a question regarding uploading files.  In this page in Django
> documentation
> 
> http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#topics-http-file-uploads,
> there is an example of handling an uploaded file like so:
>
> def handle_uploaded_file(f):
>destination = open('some/file/name.txt', 'wb+')
>for chunk in f.chunks():
>destination.write(chunk)
>destination.close()
>
> This code saves the uploaded file with the name 'name.txt'.  I
> would like to save the uploaded file with the original file name.
>  How could that be accomplished?
>
> Thank you!
> Tonu
>
>
>
>
> Uploaded files have a name attribute that contains their name.
Yes, but how does one take advantage of that in this code?

Thanks,
Tonu

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: uploading files

2009-02-17 Thread Alex Gaynor
On Tue, Feb 17, 2009 at 11:18 AM, Tonu Mikk <tm...@umn.edu> wrote:

>
> Hi Django community,
>
> I have a question regarding uploading files.  In this page in Django
> documentation
>
> http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#topics-http-file-uploads
> ,
> there is an example of handling an uploaded file like so:
>
> def handle_uploaded_file(f):
>destination = open('some/file/name.txt', 'wb+')
>for chunk in f.chunks():
>destination.write(chunk)
>destination.close()
>
> This code saves the uploaded file with the name 'name.txt'.  I would like
> to save the uploaded file with the original file name.  How could that be
> accomplished?
>
> Thank you!
> Tonu
>
>
> >
>
Uploaded files have a name attribute that contains their name.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



uploading files

2009-02-17 Thread Tonu Mikk

Hi Django community,

I have a question regarding uploading files.  In this page in Django 
documentation 
http://docs.djangoproject.com/en/dev/topics/http/file-uploads/#topics-http-file-uploads,
 
there is an example of handling an uploaded file like so:

def handle_uploaded_file(f):
destination = open('some/file/name.txt', 'wb+')
for chunk in f.chunks():
destination.write(chunk)
destination.close()

This code saves the uploaded file with the name 'name.txt'.  I would like to 
save the uploaded file with the original file name.  How could that be 
accomplished?

Thank you!
Tonu


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: UnicodeDecodeError when uploading files with non-ascii characters in filename

2008-11-27 Thread gnijholt

Thanks for the quick reply.

I almost gave up, but I just found something that seems to work for
me.

So I've tried:
---
filename = codecs.BOM_UTF8.decode(postfile['filename'])
---
...which gave a LookupError.
Then I tried casting to Unicode:
---
filename = unicode(postfile['filename'])
---
...which still raised a UnicodeDecodeError.
Then I found a solution on an issuetracker for a project on Google
Appengine.
---
filename = postfile['filename'].decode('utf-8')
---
...and this works... With even the weirdest characters.
I'm not sure what's going on but I'm glad it works.

Regards,
Gijs


On Nov 27, 3:24 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> Looking back at the commit logs, r7548 was May, 2008. Since then we've
> committed a large file system refactor, so this may well have just been
> a bug in the old system. I don't know for sure.
>
> In the new system, there still may be a non-ASCII filename handling bug,
> since ticket #9696 was opened recently. Somebody will need to look at
> the code carefully and trace through what is happening there.
>
> Somebody might have a suggestion about how to work around your
> particular problem with Django 0.96, but there isn't going to be any
> sort of fix to Django made for that, since it's code that doesn't exist
> any longer.
>
> Regards,
> Malcolm
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: UnicodeDecodeError when uploading files with non-ascii characters in filename

2008-11-26 Thread Malcolm Tredinnick


On Wed, 2008-11-26 at 06:20 -0800, gnijholt wrote:
> Hello,
> 
> I'm running Django r7548 using PostgreSQL 8.3 on Leopard.

> The problem: When I upload a file with a filename like '.jpg', I
> get the following error:
> ---
> UnicodeDecodeError at /library/documents/12114/addFile/
> 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in
> range(128)
> ---

Looking back at the commit logs, r7548 was May, 2008. Since then we've
committed a large file system refactor, so this may well have just been
a bug in the old system. I don't know for sure.

In the new system, there still may be a non-ASCII filename handling bug,
since ticket #9696 was opened recently. Somebody will need to look at
the code carefully and trace through what is happening there.

Somebody might have a suggestion about how to work around your
particular problem with Django 0.96, but there isn't going to be any
sort of fix to Django made for that, since it's code that doesn't exist
any longer.

Regards,
Malcolm


> 
> When I run codecs.BOM_UTF8.decode() on the filename, I get the
> following error:
> ---
> LookupError at /library/documents/12114/addFile/
> unknown encoding: .jpg
> ---
> 
> I've kind of run out of ideas for this problem.
> Am I missing something?
> 
> Thanks !
> 
> Gijs
> > 
> 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



UnicodeDecodeError when uploading files with non-ascii characters in filename

2008-11-26 Thread gnijholt

Hello,

I'm running Django r7548 using PostgreSQL 8.3 on Leopard.

The problem: When I upload a file with a filename like '.jpg', I
get the following error:
---
UnicodeDecodeError at /library/documents/12114/addFile/
'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in
range(128)
---

When I run codecs.BOM_UTF8.decode() on the filename, I get the
following error:
---
LookupError at /library/documents/12114/addFile/
unknown encoding: .jpg
---

I've kind of run out of ideas for this problem.
Am I missing something?

Thanks !

Gijs
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Uploading files to subdirectories

2008-05-16 Thread Mike Hjorleifsson

what happens in your example if sally has a holiday.rtf ?


On May 16, 3:00 am, James McGill <[EMAIL PROTECTED]> wrote:
> Hi All,
> I'm new to Django and I'm not sure how best to achieve the following:
>
> Users may upload files - each uploaded file is tied to a user in the
> database using a ForeignKey.
>
> In order to prevent pain to the underlying O/S I don't want to put all
> these files in to a single directory. I could separate the files by
> upload time as mentioned in the Django documentation, but it would be
> nicer to have all the files uploaded by a single user under a single
> subdirectory.
>
> Example:
> Greg uploads "holiday.rtf", it is saved as /media/uploads/greg/
> holiday.rtf
> Sally uploads "family.rtf", it is saved as /media/uploads/sally/
> family.rtf
>
> My current model:
>
> class FileModel(models.Model):
> user = models.ForeignKey(User)
> file = models.FileField(upload_to = 'uploads/'
>
> I am saving the file using FileModel_Instance.save_file_file('path',
> file_contents). Adding extra folders to the path (i.e. path = greg/
> holiday.rtf) doesn't work - I assume this is a security restriction.
>
> I am using the SVN version of Django. Any help would be appreciated.
>
> Regards,
> James
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Uploading files to subdirectories

2008-05-16 Thread Sergio

Hello James,

You can do that following this:

http://code.djangoproject.com/wiki/CustomUploadAndFilters

It uses signals to customize the upload path.

James McGill escribió:
> Hi All,
> I'm new to Django and I'm not sure how best to achieve the following:
>
> Users may upload files - each uploaded file is tied to a user in the
> database using a ForeignKey.
>
> In order to prevent pain to the underlying O/S I don't want to put all
> these files in to a single directory. I could separate the files by
> upload time as mentioned in the Django documentation, but it would be
> nicer to have all the files uploaded by a single user under a single
> subdirectory.
>
> Example:
> Greg uploads "holiday.rtf", it is saved as /media/uploads/greg/
> holiday.rtf
> Sally uploads "family.rtf", it is saved as /media/uploads/sally/
> family.rtf
>
> My current model:
>
> class FileModel(models.Model):
> user = models.ForeignKey(User)
> file = models.FileField(upload_to = 'uploads/'
>
> I am saving the file using FileModel_Instance.save_file_file('path',
> file_contents). Adding extra folders to the path (i.e. path = greg/
> holiday.rtf) doesn't work - I assume this is a security restriction.
>
> I am using the SVN version of Django. Any help would be appreciated.
>
> Regards,
> James
>
>
> >
>   


-- 
   Un saludote..
 --==@ Sergio @==--

Barraquito.net - http://www.barraquito.net


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Uploading files to subdirectories

2008-05-16 Thread James McGill

Hi All,
I'm new to Django and I'm not sure how best to achieve the following:

Users may upload files - each uploaded file is tied to a user in the
database using a ForeignKey.

In order to prevent pain to the underlying O/S I don't want to put all
these files in to a single directory. I could separate the files by
upload time as mentioned in the Django documentation, but it would be
nicer to have all the files uploaded by a single user under a single
subdirectory.

Example:
Greg uploads "holiday.rtf", it is saved as /media/uploads/greg/
holiday.rtf
Sally uploads "family.rtf", it is saved as /media/uploads/sally/
family.rtf

My current model:

class FileModel(models.Model):
user = models.ForeignKey(User)
file = models.FileField(upload_to = 'uploads/'

I am saving the file using FileModel_Instance.save_file_file('path',
file_contents). Adding extra folders to the path (i.e. path = greg/
holiday.rtf) doesn't work - I assume this is a security restriction.

I am using the SVN version of Django. Any help would be appreciated.

Regards,
James


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Uploading files

2007-09-14 Thread Russell Keith-Magee

On 9/14/07, Dushyant Sharma <[EMAIL PROTECTED]> wrote:
>
> def thing_add(request):
> if request.method == 'POST':
> new_data = request.POST.copy()
> new_data.update(request.FILES)

This example is incorrect for the current trunk version of Django. You
don't update the request.FILES into request.POST - you pass in the
FILES data as a second argument to the form.

This obviously needs to be documented better - please raise a ticket
so that it doesn't get forgotten.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Uploading files

2007-09-14 Thread Dushyant Sharma


class ThingForm(forms.Form):
name = forms.CharField(max_length=30, required=True, label=_('Name
of the thing'))
photo = forms.Field(widget=forms.FileInput, required=False,
label=_('Photo'), help_text=_('Upload an image (max %s kilobytes)' %
settings.MAX_PHOTO_UPLOAD_SIZE))

def thing_add(request):
if request.method == 'POST':
new_data = request.POST.copy()
new_data.update(request.FILES)
form = ThingForm(new_data)
if form.is_valid():
clean_data = form.clean_data
t = Thing()
t.name = clean_data['name']
if clean_data['photo']:
photo = clean_data['photo']
t.save_photo_file(photo['filename'], photo['content'])

please also read
http://www.djangoproject.com/documentation/model-api/#filefield
and
http://batiste.dosimple.ch/blog/2007-05-13-1/

new forms have changed this binding and made things easy so you can
also check
http://www.djangoproject.com/documentation/newforms/#binding-uploaded-files-to-a-form


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Uploading files

2007-09-14 Thread Jarek Zgoda

Jarek Zgoda napisał(a):

>>  I am using Django 0.97 pre in winxp. database is mysql. Please
>> forgive any errors or if I am not clear with some aspects as I am a
>> beginner trying to learn django. I am trying to upload a file: an
>> image. I am not worried about validation now. I want to know how to do
>> this.
>> I tried to do this But my data base shows only the name of the file
>> uploaded (I think it should store the path to the file).
>>   In my view I have
>>
>> def save_data(request):
>>
>> ed_user=getfrmdb(uid)
>> new_data=request.POST.copy()   #this accounts for uploading the
>> image too with other data.
>> print new_data
>> addata=User(id=uid,name=ed_user.name, email=new_data['u_email'],
>>  
>> address=new_data['u_add'],phone=new_data['u_ph'],date=datetime.date.today(),
>> comments=new_data['u_comm'], image=  __)
>> addata.save()
>>
>> I saw some codes (with new_data.update(request.FILES) )but I have a
>> hard time in understanding it completely.
>>I would also like to know important tips to retrieve this uploaded
>> image. Thanking you ..
> 
> It would be great if somebody wrote a quick introduction to handling
> file/image uploads in Django using both newforms and oldforms. I barely
> understand how it works, so I will not even try now...

Also, I found some related (but unanswered) question asked on this group
long time ago, which touches the topic of some importance if somebody
wants to store uploaded files outside MEDIA_ROOT. I think it's a common
case to not store user-submitted content along with static site content,
but in current state I just don't know how to achieve this...

http://groups.google.com/group/django-users/msg/f518a9e7579bf47e

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Uploading files

2007-09-14 Thread Jarek Zgoda

AniNair napisał(a):

>  I am using Django 0.97 pre in winxp. database is mysql. Please
> forgive any errors or if I am not clear with some aspects as I am a
> beginner trying to learn django. I am trying to upload a file: an
> image. I am not worried about validation now. I want to know how to do
> this.
> I tried to do this But my data base shows only the name of the file
> uploaded (I think it should store the path to the file).
>   In my view I have
> 
> def save_data(request):
> 
> ed_user=getfrmdb(uid)
> new_data=request.POST.copy()   #this accounts for uploading the
> image too with other data.
> print new_data
> addata=User(id=uid,name=ed_user.name, email=new_data['u_email'],
>  
> address=new_data['u_add'],phone=new_data['u_ph'],date=datetime.date.today(),
> comments=new_data['u_comm'], image=  __)
> addata.save()
> 
> I saw some codes (with new_data.update(request.FILES) )but I have a
> hard time in understanding it completely.
>I would also like to know important tips to retrieve this uploaded
> image. Thanking you ..

It would be great if somebody wrote a quick introduction to handling
file/image uploads in Django using both newforms and oldforms. I barely
understand how it works, so I will not even try now...

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Uploading files

2007-09-14 Thread AniNair

Hello,
 I am using Django 0.97 pre in winxp. database is mysql. Please
forgive any errors or if I am not clear with some aspects as I am a
beginner trying to learn django. I am trying to upload a file: an
image. I am not worried about validation now. I want to know how to do
this.
I tried to do this But my data base shows only the name of the file
uploaded (I think it should store the path to the file).
  In my view I have

def save_data(request):

ed_user=getfrmdb(uid)
new_data=request.POST.copy()   #this accounts for uploading the
image too with other data.
print new_data
addata=User(id=uid,name=ed_user.name, email=new_data['u_email'],
 
address=new_data['u_add'],phone=new_data['u_ph'],date=datetime.date.today(),
comments=new_data['u_comm'], image=  __)
addata.save()

I saw some codes (with new_data.update(request.FILES) )but I have a
hard time in understanding it completely.
   I would also like to know important tips to retrieve this uploaded
image. Thanking you ..


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: 500 Errors when uploading files (with FastCGI)

2007-06-26 Thread Dirk van Oosterbosch, IR labs
Replying myself to add some information and ask some extra questions.

I just had contact with the maintainer of my shared host. He warned  
that memory exceeding the (shared usage) limit could cause strange  
errors. And that memory usage should be dealt with carefully.
He adviced me to save the uploaded files directly to disk instead of  
storing them in memory first. Can I do this at all with Django?

I am now using (in the view)
if request.method == 'POST':
if 'uploadedfile' in request.FILES:
new_data = request.POST.copy()
new_data.update(request.FILES)
form = UploadForm(new_data)
if form.is_valid():
success = form.save(request.user)

in the UploadForm class
def clean_uploadedfile(self):
file_data = self.clean_data['uploadedfile']

return file_data

in save()
if self.clean_data['uploadedfile']:
uploadedfile_data = self.clean_data['uploadedfile']
file_path = "path/to/saved/file/%s" % 
(uploadedfile_data['filename'])
save_content_to_file(file_path, 
uploadedfile_data['content'])

and only finally in save_content_to_file()
def save_content_to_file(filename, content):
try:
fileObj = open(filename, "wb")
try:
fileObj.write(content)
finally:
fileObj.close()


So I am guessing I'm consuming quite some memory to deal with this  
incoming request data.
How could I improve my code, so it will use its memory a bit more  
economically?

And is there a way to have the files in the requested post data  
streamed into files on disk directly?

Thanks,
dirk






On 26-jun-2007, at 17:36, Dirk van Oosterbosch, IR labs wrote:

> Hi All,
>
> I deployed an app with uploading functionality to a server running  
> FastCGI.
> When I had it tested by my users, the site became completely  
> unresponsive, returning nothing but Error 500's.
>
> In the log I find a lot of these:
> Unhandled exception in thread started by  ThreadPool._worker of  0x825e10>>
> Traceback (most recent call last):
> File "/usr/local/lib/python2.5/site-packages/flup-0.5-py2.5.egg/ 
> flup/server/threadpool.py", line 103, in _worker
> job.run()
> File "/usr/local/lib/python2.5/site-packages/flup-0.5-py2.5.egg/ 
> flup/server/fcgi_base.py", line 645, in run
> except (select.error, socket.error), e:
> AttributeError: 'NoneType' object has no attribute 'error'
>
> Does anybody know, what could cause this or (better yet) how to fix  
> it?
> best
> dirk



-
Dirk van Oosterbosch
de Wittenstraat 225
1052 AT Amsterdam
the Netherlands

http://labs.ixopusada.com
-



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Strange Errors with FastCGI when uploading files

2007-06-26 Thread Dirk van Oosterbosch, IR labs
Hi All,

I deployed an app with uploading functionality to a server running  
FastCGI.
When I had it tested by my users, the site became completely  
unresponsive, returning nothing but Error 500's.

In the log I find a lot of these:
Unhandled exception in thread started by >
Traceback (most recent call last):
   File "/usr/local/lib/python2.5/site-packages/flup-0.5-py2.5.egg/ 
flup/server/threadpool.py", line 103, in _worker
 job.run()
   File "/usr/local/lib/python2.5/site-packages/flup-0.5-py2.5.egg/ 
flup/server/fcgi_base.py", line 645, in run
 except (select.error, socket.error), e:
AttributeError: 'NoneType' object has no attribute 'error'

Does anybody know, what could cause this or (better yet) how to fix it?
best
dirk



-
Dirk van Oosterbosch
de Wittenstraat 225
1052 AT Amsterdam
the Netherlands

http://labs.ixopusada.com
-



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Uploading Files

2006-09-10 Thread Andres Luga

Hi, relarted to this topic.

When using generic views, how to achieve that the file doesn't get
overwritten? For example a form for editing a person: the image file
field has no default data and when I only change the name the image is
blanked. It seems I missed something..

Regards,
Andres

> http://www.djangoproject.com/documentation/model_api/#imagefield

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Uploading Files

2006-09-08 Thread Andy Dustman

On 9/8/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> how can I upload file to /media/images/1.jpg with Django?

Start here:

http://www.djangoproject.com/documentation/model_api/#imagefield

If the admin interface is sufficient for you, you're done. Note that
this requires an object/row per image.
-- 
This message has been scanned for memes and
dangerous content by MindScanner, and is
believed to be unclean.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Uploading Files

2006-09-08 Thread [EMAIL PROTECTED]

Hello,
how can I upload file to /media/images/1.jpg with Django?
Thak you for help.

P.S. Sorry for may bad English ;-)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---