upload - can I get the path to original file

80 views
Skip to first unread message

jim kaubisch

unread,
Oct 4, 2019, 3:07:06 PM10/4/19
to web2py-users
Hi

In a file upload, I want to store both the original filename AND the path to the original file (to cover the case of files with the same name but from different folders)
I'm successfully getting the filename from "request.vars.the_file.filename" as documented, but is there somewhere I can retrieve the path?

Thanks

Paco Bernal

unread,
Oct 4, 2019, 5:18:26 PM10/4/19
to web2py-users
HI


db.define_table('logos',
Field('logo', 'upload', uploadfolder='applications/%s/%s' % (request.application, 'uploads'), uploadseparate=True, autodelete=True),
Field('thumbnail', 'upload', uploadfolder='applications/%s/%s' % (request.application, 'uploads'), uploadseparate=True, autodelete=True, compute = lambda row: thumb(row.logo, 90, 90, 'logos.logo')),
)

path = '%suploads/%s/%s/%s' % (request.folder, where, image[start:end], image)

"where" depends on the field and table names, table logos and field logo

and thumb is a module for getting a thumbnail of the picture


def thumb(
  from gluon import current
  import os
  from PIL import Image
  request = current.request
  start = len(where)+1
  end = len(where)+3
  img = Image.open('%suploads/%s/%s/%s' % (request.folder, where, image[start:end], image))
  img.thumbnail((nx, ny), Image.ANTIALIAS)
  root, ext = os.path.splitext(image)
  thumb = '%s_%s_%sx%s%s' % (root, name, nx, ny, ext)
  img.save('%suploads/%s/%s/%s' % (request.folder, where, image[start:end], thumb))
  #~ print 'thumb', thumb
  return thumb

Regards

Dave S

unread,
Oct 7, 2019, 3:15:39 AM10/7/19
to web2py-users
If you want the path on the client machine, no can do.  Browsers don't share this as it is a privacy/security issue. The client filesystem is opaque to the server.  

You can ask the client to enter the value themselves as an explicit field on your form, but they may choose not to, especially if they are concerned about the privacy/security issue.

 /dps

jim kaubisch

unread,
Oct 8, 2019, 1:56:31 PM10/8/19
to web2py-users


On Friday, October 4, 2019 at 12:07:06 PM UTC-7, jim kaubisch wrote:
Thanks, Dave
As I read your reply, I remembered I'd hit this issue previously :-(  

Reply all
Reply to author
Forward
0 new messages