Re: [google-appengine] Re: Blobstore file upload with other form values

2011-02-13 Thread Robert Kluin
Hi,
  You're getting the IndexError because get_uploads is returning an
empty list, which means there are no blob-info records for the 'file'
field.

  Your other error is because BlobstoreUploadHandler only allows
redirects.  Like Doug suggests, you'll need to redirect to another
page to output something.



Robert





On Sun, Feb 13, 2011 at 02:51, theone maliha...@gmail.com wrote:
 I don't need to return the values. My problem is that while I am able
 to send file with a few form fields, It gives an error using many
 fields:
 w=upload_files[0]
 IndexError: list index out of range
 INFO     2011-02-13 07:43:10,884 dev_appserver_blobstore.py:328]
 Upload handler returned 500
 ERROR    2011-02-13 07:43:10,884 dev_appserver_blobstore.py:341]
 Invalid upload handler response. Only 301, 302 and 303 statuses are
 permitted and it may not have a content body.
 INFO     2011-02-13 07:43:10,910 dev_appserver.py:3317] POST /_ah/
 upload/agZlcGN2ZGJyHAsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxjFAgw HTTP/1.1
 500 -

 In both cases I use the same definitions:
 upload_files = self.get_uploads('file')
 w=upload_files[0]



 On Feb 13, 9:35 am, Doug Anderson d...@solipsis.com wrote:
 I have to retract my previous post... this does appear to be working
 for me.  I can use self.request.get('description') to retrieve the
 text description form field.  My previous problem was that
 name='descripton' was spelled wrong in my html form (missing the last
 'i')... doh!

 I think your issue is that you lose your self.response.out.write(N)
 content when you redirect via return self.redirect('/')... that
 response body content won't survive the redirect (the redirect will
 provide its own content).  If you need to return the submitted N and S
 content then perhaps you could redirect to a URL that takes the 'a'
 object key as a parameter self.redirect('/' +
 urllib.quote(a.key())).  Of course you'd have to setup your handler
 to accept the parameter... but then you could re-retrieve 'a' object
 in the handler via a datastore get such as a = db.get(a_key)...
 assuming 'a_key' is the name of the parameter.

 On Feb 13, 1:54 am, theone maliha...@gmail.com wrote:







  I think you are right about BlobstoreUploadHandler limitations. When I
  tried something like:
  class X(db.Model):
      N = db.StringProperty()
      S = db.StringProperty()
      F = blobstore.BlobReferenceProperty()

  class Upload(blobstore_handlers.BlobstoreUploadHandler):
      def post(self):
          upload_files = self.get_uploads('file')
          a=upload_files[0]
          N = self.request.get('name')
          S = self.request.get('sname')
          if S:
              m=N + S
          else:
              m=S + N
          self.response.out.write(N)
          self.response.out.write(S)
          a=X(N=m, S=S, F=a)
          a.put()
          return self.redirect('/')

  It worked partly. I mean I put my model to datastore and file to
  blobstore. However, it does not writes the thing like:
  self.response.out.write(N). What I understand here we cannot use
  everything in BlobstoreUploadHandler.

  Also if you request the form fields, it does not work.

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



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



[google-appengine] Re: Blobstore file upload with other form values

2011-02-13 Thread theone
Thank you. I solved the problem. In my html form I forgot to put
enctype=multipart/form-data. It seems working now.

On Feb 13, 9:12 pm, Robert Kluin robert.kl...@gmail.com wrote:
 Hi,
   You're getting the IndexError because get_uploads is returning an
 empty list, which means there are no blob-info records for the 'file'
 field.

   Your other error is because BlobstoreUploadHandler only allows
 redirects.  Like Doug suggests, you'll need to redirect to another
 page to output something.

 Robert







 On Sun, Feb 13, 2011 at 02:51, theone maliha...@gmail.com wrote:
  I don't need to return the values. My problem is that while I am able
  to send file with a few form fields, It gives an error using many
  fields:
  w=upload_files[0]
  IndexError: list index out of range
  INFO     2011-02-13 07:43:10,884 dev_appserver_blobstore.py:328]
  Upload handler returned 500
  ERROR    2011-02-13 07:43:10,884 dev_appserver_blobstore.py:341]
  Invalid upload handler response. Only 301, 302 and 303 statuses are
  permitted and it may not have a content body.
  INFO     2011-02-13 07:43:10,910 dev_appserver.py:3317] POST /_ah/
  upload/agZlcGN2ZGJyHAsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxjFAgw HTTP/1.1
  500 -

  In both cases I use the same definitions:
  upload_files = self.get_uploads('file')
  w=upload_files[0]

  On Feb 13, 9:35 am, Doug Anderson d...@solipsis.com wrote:
  I have to retract my previous post... this does appear to be working
  for me.  I can use self.request.get('description') to retrieve the
  text description form field.  My previous problem was that
  name='descripton' was spelled wrong in my html form (missing the last
  'i')... doh!

  I think your issue is that you lose your self.response.out.write(N)
  content when you redirect via return self.redirect('/')... that
  response body content won't survive the redirect (the redirect will
  provide its own content).  If you need to return the submitted N and S
  content then perhaps you could redirect to a URL that takes the 'a'
  object key as a parameter self.redirect('/' +
  urllib.quote(a.key())).  Of course you'd have to setup your handler
  to accept the parameter... but then you could re-retrieve 'a' object
  in the handler via a datastore get such as a = db.get(a_key)...
  assuming 'a_key' is the name of the parameter.

  On Feb 13, 1:54 am, theone maliha...@gmail.com wrote:

   I think you are right about BlobstoreUploadHandler limitations. When I
   tried something like:
   class X(db.Model):
       N = db.StringProperty()
       S = db.StringProperty()
       F = blobstore.BlobReferenceProperty()

   class Upload(blobstore_handlers.BlobstoreUploadHandler):
       def post(self):
           upload_files = self.get_uploads('file')
           a=upload_files[0]
           N = self.request.get('name')
           S = self.request.get('sname')
           if S:
               m=N + S
           else:
               m=S + N
           self.response.out.write(N)
           self.response.out.write(S)
           a=X(N=m, S=S, F=a)
           a.put()
           return self.redirect('/')

   It worked partly. I mean I put my model to datastore and file to
   blobstore. However, it does not writes the thing like:
   self.response.out.write(N). What I understand here we cannot use
   everything in BlobstoreUploadHandler.

   Also if you request the form fields, it does not work.

  --
  You received this message because you are subscribed to the Google Groups 
  Google App Engine group.
  To post to this group, send email to google-appengine@googlegroups.com.
  To unsubscribe from this group, send email to 
  google-appengine+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/google-appengine?hl=en.

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



[google-appengine] Re: Blobstore file upload with other form values

2011-02-12 Thread Doug Anderson
FWIW I'm facing the same problem and I'm reasonably certain the issue is 
simply a limitation of the BlobstoreUploadHandler.  The handler stores 
uploaded blobs perfectly fine and gives your handler the BlobInfo for each 
blob BUT it seems to discard any non file (type='file') form fields.  So if 
you want to upload a text description along with a photo you're out of luck 
(using the blobstore).  I don't actually want the text description stored in 
the blobstore but I'd like it passed to the handler so I can store it in the 
datastore.

PLEASE FIX this blobstore upload issue... please make other (non file) form 
fields available to BlobstoreUploadHandler derived classes.  Thank you!

On a separate note I'm really looking forward to the programmatic access to 
the blobstore that I see listed on the roadmap!

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



[google-appengine] Re: Blobstore file upload with other form values

2011-02-12 Thread theone
I think you are right about BlobstoreUploadHandler limitations. When I
tried something like:
class X(db.Model):
N = db.StringProperty()
S = db.StringProperty()
F = blobstore.BlobReferenceProperty()

class Upload(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('file')
a=upload_files[0]
N = self.request.get('name')
S = self.request.get('sname')
if S:
m=N + S
else:
m=S + N
self.response.out.write(N)
self.response.out.write(S)
a=X(N=m, S=S, F=a)
a.put()
return self.redirect('/')

It worked partly. I mean I put my model to datastore and file to
blobstore. However, it does not writes the thing like:
self.response.out.write(N). What I understand here we cannot use
everything in BlobstoreUploadHandler.

Also if you request the form fields, it does not work.

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



[google-appengine] Re: Blobstore file upload with other form values

2011-02-12 Thread theone
Hi Robert,

Thank you for your advices. I did not checked my logs before you
said.

When I checked my logs, it gives:

w=upload_files[0]
IndexError: list index out of range
INFO 2011-02-13 07:17:39,486 dev_appserver_blobstore.py:328]
Upload handler returned 500
ERROR2011-02-13 07:17:39,486 dev_appserver_blobstore.py:341]
Invalid upload handler response. Only 301, 302 and 303 statuses are
permitted and it may not have a content body.
INFO 2011-02-13 07:17:39,509 dev_appserver.py:3317] POST /_ah/
upload/agZlcGN2ZGJyHAsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxi_Agw HTTP/1.1
500 -

As I understand from it, It could not get the file so it gives list
index out of range error. However, in another application I use the
same structure and it does not give any error.

Any suggestion about that?

On Feb 13, 6:38 am, Robert Kluin robert.kl...@gmail.com wrote:
 Some thoughts / suggestions:
   1) Check your url to handler mappings. Both in app.yaml and in your
 WSGI app definition.
   2) Check the logs to see what urls are actually getting hit.
   3) At some point in the Upload handler you do create and put a new
 Expert entity, right?

 Robert







 On Sat, Feb 12, 2011 at 06:41, theone maliha...@gmail.com wrote:
  Hello,

  I want to keep user information and files with blobstore but I could
  not do it.
  I have a structure like:

  class Expert(db.Model):
         N = db.StringProperty(indexed=True, required=True,
  verbose_name='Name')
         S = db.StringProperty(indexed=True, required=True,
  verbose_name='Surname')
         BD = db.DateProperty(indexed=True, required=True, verbose_name='Birth
  Date')
         EY = db.IntegerProperty(indexed=True, verbose_name='Years of
  Experience')

  class AddExpert(webapp.RequestHandler):
                 upload_url = blobstore.create_upload_url('/upload')
                 doRender(self, addexpert.htm, {'upload_url': upload_url } )

  and html form like:

  form id=upload_form action={{ upload_url }} enctype=multipart/
  form-data method=post
  table
   trtd class=leftcolumnName/tdtdinput type=text
  name=name //td/tr
   trtd class=leftcolumnSurname/tdtdinput type=text
  name=surname //td/tr
  

  when I tried to upload my data and redirect my page:

  class Upload(blobstore_handlers.BlobstoreUploadHandler):
     def post(self):
         upload_files = self.get_uploads('file')
         blob_info = upload_files[0]
         blob = blob_info.key()
         N = self.request.get('name')
         S = self.request.get('surname')
         ..
         self.redirect('/')

  It redirects to an empty page. It saves the file at __BlobInfo__ (I
  could see it at SDK console) but it does not save other information.

  Am I missing any point?
  Thanks for helps in advance.

  --
  You received this message because you are subscribed to the Google Groups 
  Google App Engine group.
  To post to this group, send email to google-appengine@googlegroups.com.
  To unsubscribe from this group, send email to 
  google-appengine+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://groups.google.com/group/google-appengine?hl=en.

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



[google-appengine] Re: Blobstore file upload with other form values

2011-02-12 Thread Doug Anderson
I have to retract my previous post... this does appear to be working
for me.  I can use self.request.get('description') to retrieve the
text description form field.  My previous problem was that
name='descripton' was spelled wrong in my html form (missing the last
'i')... doh!

I think your issue is that you lose your self.response.out.write(N)
content when you redirect via return self.redirect('/')... that
response body content won't survive the redirect (the redirect will
provide its own content).  If you need to return the submitted N and S
content then perhaps you could redirect to a URL that takes the 'a'
object key as a parameter self.redirect('/' +
urllib.quote(a.key())).  Of course you'd have to setup your handler
to accept the parameter... but then you could re-retrieve 'a' object
in the handler via a datastore get such as a = db.get(a_key)...
assuming 'a_key' is the name of the parameter.


On Feb 13, 1:54 am, theone maliha...@gmail.com wrote:
 I think you are right about BlobstoreUploadHandler limitations. When I
 tried something like:
 class X(db.Model):
     N = db.StringProperty()
     S = db.StringProperty()
     F = blobstore.BlobReferenceProperty()

 class Upload(blobstore_handlers.BlobstoreUploadHandler):
     def post(self):
         upload_files = self.get_uploads('file')
         a=upload_files[0]
         N = self.request.get('name')
         S = self.request.get('sname')
         if S:
             m=N + S
         else:
             m=S + N
         self.response.out.write(N)
         self.response.out.write(S)
         a=X(N=m, S=S, F=a)
         a.put()
         return self.redirect('/')

 It worked partly. I mean I put my model to datastore and file to
 blobstore. However, it does not writes the thing like:
 self.response.out.write(N). What I understand here we cannot use
 everything in BlobstoreUploadHandler.

 Also if you request the form fields, it does not work.

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



[google-appengine] Re: Blobstore file upload with other form values

2011-02-12 Thread theone
I don't need to return the values. My problem is that while I am able
to send file with a few form fields, It gives an error using many
fields:
w=upload_files[0]
IndexError: list index out of range
INFO 2011-02-13 07:43:10,884 dev_appserver_blobstore.py:328]
Upload handler returned 500
ERROR2011-02-13 07:43:10,884 dev_appserver_blobstore.py:341]
Invalid upload handler response. Only 301, 302 and 303 statuses are
permitted and it may not have a content body.
INFO 2011-02-13 07:43:10,910 dev_appserver.py:3317] POST /_ah/
upload/agZlcGN2ZGJyHAsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxjFAgw HTTP/1.1
500 -

In both cases I use the same definitions:
upload_files = self.get_uploads('file')
w=upload_files[0]



On Feb 13, 9:35 am, Doug Anderson d...@solipsis.com wrote:
 I have to retract my previous post... this does appear to be working
 for me.  I can use self.request.get('description') to retrieve the
 text description form field.  My previous problem was that
 name='descripton' was spelled wrong in my html form (missing the last
 'i')... doh!

 I think your issue is that you lose your self.response.out.write(N)
 content when you redirect via return self.redirect('/')... that
 response body content won't survive the redirect (the redirect will
 provide its own content).  If you need to return the submitted N and S
 content then perhaps you could redirect to a URL that takes the 'a'
 object key as a parameter self.redirect('/' +
 urllib.quote(a.key())).  Of course you'd have to setup your handler
 to accept the parameter... but then you could re-retrieve 'a' object
 in the handler via a datastore get such as a = db.get(a_key)...
 assuming 'a_key' is the name of the parameter.

 On Feb 13, 1:54 am, theone maliha...@gmail.com wrote:







  I think you are right about BlobstoreUploadHandler limitations. When I
  tried something like:
  class X(db.Model):
      N = db.StringProperty()
      S = db.StringProperty()
      F = blobstore.BlobReferenceProperty()

  class Upload(blobstore_handlers.BlobstoreUploadHandler):
      def post(self):
          upload_files = self.get_uploads('file')
          a=upload_files[0]
          N = self.request.get('name')
          S = self.request.get('sname')
          if S:
              m=N + S
          else:
              m=S + N
          self.response.out.write(N)
          self.response.out.write(S)
          a=X(N=m, S=S, F=a)
          a.put()
          return self.redirect('/')

  It worked partly. I mean I put my model to datastore and file to
  blobstore. However, it does not writes the thing like:
  self.response.out.write(N). What I understand here we cannot use
  everything in BlobstoreUploadHandler.

  Also if you request the form fields, it does not work.

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