On Friday, February 2, 2018 at 5:04:26 PM UTC-5, David Orme wrote: > > Hi, > > I'm collecting dataset files from users. There can be several versions as > problems with the files get fixed and I want to organise the uploaded files > by their common dataset id. So in my controller I do this: > > # set the upload directory locally > upload_dir = os.path.join(request.folder, 'uploads', 'datasets', str( > new_ds_id)) > db.datasets.file.uploadfolder = upload_dir > > # Setup the form > form = SQLFORM(db.datasets, > record = record, > fields=['project_id', 'file'], > showid=False, > deletable=False, > button='Upload') > > That works really nicely and I just have to remember to use that path > where I need to find the file within the code. > > However, I can't work out how to get the download controller to work with > the folder structure. For example, I'm currently using SQLFORM.grid to > provide a table of uploaded datasets, and when users click through to view > a particular record then they get the nice automatically generated file > download link. Unfortunately, that has no idea that there is the extra > component in the path, so it doesn't work. > > I've had a look at the source for response.download, heading into > field.retrieve and it looks like I should be able to set a custom_retrieve, > but I can't find example usage. > Any suggestions? >
The downside of custom_retrieve is that you've got to custom code a lot of additional logic just so you can specify a custom path. Is it feasible to include new_ds_id in the link (as an arg or var)? If so, either in the model code or in the download function, you can set the custom uploadfolder based on that value. Alternatively, you could do a query for the filename to retrieve the database record and get the new_ds_id from there, and then set the custom uploadfolder. Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.