This is great - works perfectly.
Thanks again for all the help!
j
On Wednesday, October 16, 2013 8:46:46 AM UTC-7, Anthony wrote:
>
> Sorry, turns out the filename stored in the db must be the *last* URL
> argument, not the first -- so the order of the URL args should be reversed.
> Actually, there are some limitations regarding characters allowed in URL
> args, so it might be a better idea to put the new filename in the query
> string (i.e., a URL variable):
>
> URL('default', 'download', args=download_path, vars=dict(filename=
> 'new_title'))
>
> The download function would then be:
>
> def download():
> return response.download(request, db, download_filename=request.vars.
> filename)
>
> And yes, the new file name will appear in the URL -- that's how it is
> communicated to the download function.
>
> Anthony
>
> On Wednesday, October 16, 2013 11:31:49 AM UTC-4, Jordan Ladora wrote:
>>
>> Hi Anthony,
>>
>> Thanks for the help.
>>
>> The download_path variable doesn't change regardless of whether the
>> download() function includes, or is passed, the 'download_filename' arg.
>> Indeed, the file downloads successfully when the download function is the
>> default, ie -
>>
>> def download():
>> return response.download(request, db)
>>
>> ..and when download() is called with just this one arg -
>>
>> <td>{{=A('Download', _href=URL('default', 'download',
>> args=download_path))}}</td>
>>
>>
>> When I added the second parameter to the call to download()-
>>
>> <td>{{=A('Download w title', _href=URL('default', 'download',
>> args=[download_path, 'new_title']))}}</td>
>>
>> ..I changed the download() function in the default controller to this-
>>
>> def download():
>> return response.download(request, db, attachment=True,
>> download_filename=request.args(1))
>>
>>
>> The db field from the model looks like this-
>> Field('file', 'upload', length=128, autodelete=True,
>> requires=IS_NOT_EMPTY()),
>>
>>
>> It might be most telling to show the links that are generated in the
>> view.. the [working] link for -
>> <td>{{=A('Download', _href=URL('default', 'download',
>> args=download_path))}}</td>
>>
>> ..looks like:
>>
>> http://127.0.0.1:8000/test_app/default/download/main_db.file.b36e427143f2c727.64633532346236612d373033622d343235352d383330302d616362613637366136396262.txt
>>
>>
>> And the link for -
>> <td>{{=A('Download w title', _href=URL('default', 'download',
>> args=[download_path, 'new_title']))}}</td>
>>
>> ..looks like:
>>
>> http://127.0.0.1:8000/test_app/default/download/main_db.file.b36e427143f2c727.64633532346236612d373033622d343235352d383330302d616362613637366136396262.txt/new_title
>>
>>
>> The latter generates the 404 error. As you can see, when I add the
>> 'download_filename' arg, a new path is generated with the desired filename
>> appended to the path, which doesn't seem to make sense.
>>
>> Thanks again for your help. Let me know if there is any more info I can
>> provide.
>>
>> Cheers,
>> jl
>>
>>
>>
>>
>>
>> On Tuesday, October 15, 2013 8:21:42 PM UTC-7, Anthony wrote:
>>>
>>> We need to see more code -- maybe your model and the code that generates
>>> the value of download_path. response.download() will return a 404 if the
>>> filename is not of the right format, it can't find the table/field, or it
>>> can't retrieve the file.
>>>
>>> Anthony
>>>
>>> On Tuesday, October 15, 2013 10:06:45 PM UTC-4, Jordan Ladora wrote:
>>>>
>>>> Ha! Thanks for that.. I upgraded to 2.7.4. but get 404 not found when I
>>>> use Anthony's code..
>>>>
>>>> in the view-
>>>>
>>>> <td>{{=A('Download', _href=URL('default', 'download',
>>>> args=download_path))}}</td>
>>>> <td>{{=A('Download w title', _href=URL('default', 'download',
>>>> args=[download_path, 'new_title']))}}</td>
>>>>
>>>>
>>>> in default.py-
>>>>
>>>> @auth.requires_login()
>>>> def download():
>>>> """
>>>> allows downloading of uploaded files
>>>> http://..../[app]/default/download/[filename]
>>>> """
>>>> ## response.download(self, request, db,
>>>> chunk_size=DEFAULT_CHUNK_SIZE, attachment=True, download_filename=None):
>>>> return response.download(request, db,
>>>> download_filename=request.args(1))
>>>>
>>>>
>>>> ...hopefully there is something else silly that i am doing wrong
>>>> here...?
>>>>
>>>> Thanks,
>>>> jl
>>>>
>>>>
>>>> On Tuesday, October 15, 2013 3:01:49 PM UTC-7, Niphlod wrote:
>>>>>
>>>>> You're using an old version of web2py :D
>>>>>
>>>>> On Tuesday, October 15, 2013 11:40:55 PM UTC+2, Jordan Ladora wrote:
>>>>>>
>>>>>> Err.. I get an unknown parameter error for the 'download_filename' ..
>>>>>> looking into globals.py I see
>>>>>>
>>>>>> def download(self, request, db, chunk_size=DEFAULT_CHUNK_SIZE,
>>>>>> attachment=True):
>>>>>>
>>>>>> so I'm not sure about where this parameter goes(?)
>>>>>>
>>>>>> Thanks,
>>>>>> -j
>>>>>>
>>>>>>>
>>>>>>>
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.