Hello Anthony,
I'll try to do according to the book but unfortunately it won't work.
import os
user_name = request.vars['user_name']
path_ = "/var/www-data/web2py/applications/app_name/uploads/%s" % user_name
db.define_table('media',
Field('user_name', 'string', length=30, required=True),
Field('file_name', 'string', length=30, required =True),
Field('file_', uploadfolder=path))
#uploadfolder=os.path.join(request.user_name, path))), 'upload')
Upload function in the controller
# Create folder(name it as username) upload file to that folder.
def upload_File():
if request.vars['user_name'] is not None:
user_name = request.vars['user_name']
file_name = request.vars['file_name']
row = db(db.driver.user_name==user_name).select().first()
path = "/var/www-data/web2py/applications/app_name/uploads/%s" %
user_name
if row is not None:
if not os.path.exists(path):
os.makedirs(path)
if request.vars['upload'] is not None:
uploadedFile = request.vars['upload']
inserted_id =
db.media.insert(user_name=user_name,file_name=file_name, file_=uploadedFile)
return "Inserted file ID: %s, folder created %s" %
(inserted_id, user_name)
return 'Username "%s" does not exist or file wasn\'t chosen' % user_name
if i user 'upload' file uploaded in the uploads folder (as it should) and I
can download file by clicking "file" link in the "Database db select" as
shown in the pic
But if I use:
import os
user_name = request.vars['user_name']
path_ = "/var/www-data/web2py/applications/app_name/uploads/%s" % user_name
db.define_table('media',
Field('user_name', 'string', length=30, required=True),
Field('file_name', 'string', length=30, required =True),
Field('file_', uploadfolder=path)) # or this ->
uploadfolder=os.path.join(request.user_name, path))),
In "database db select" changes file downloading link "file" as shown in
pic.:
is this therefore download function? if it is how should I modify it or
create new one? if not please redirect to the solution.
Thank you.
On Monday, August 3, 2015 at 11:33:56 PM UTC+3, Anthony wrote:
>
> You could follow this method to store the original filenames:
> http://web2py.com/books/default/chapter/29/07/forms-and-validators#Storing-the-original-filename
> .
>
> Anthony
>
> On Monday, August 3, 2015 at 3:52:19 PM UTC-4, Vladimiras Lomovas wrote:
>>
>> Thank you for such quick answer.
>> Could you suggest solution(or where to look) on returning list of
>> uploaded files(without renaming them or otherwise) for the user to view or
>> download them?
>>
>>
>> On Monday, August 3, 2015 at 3:55:12 AM UTC+3, Massimo Di Pierro wrote:
>>>
>>> web2py exposes only actions, not all functions. An action is a function
>>> in a controller that takes no arguments and does not start with two
>>> underscores.
>>>
>>> Be very careful with using the original filename as name of the file.
>>> There are many possible vulnerabilities associated with this behavior,
>>> including directory traversal. This is why most frameworks, including
>>> web2py, rename files on upload. Consider that the sender can inject any
>>> character it in filename and that character may have a special meaning on
>>> your filesystem (think of / \ : for example). Also consider a file with
>>> that name many already exist.
>>>
>>> Massimo
>>>
>>>
>>> On Sunday, 2 August 2015 18:56:37 UTC-5, Vladimiras Lomovas wrote:
>>>>
>>>>
>>>> <https://lh3.googleusercontent.com/-rj-e4oMWCIk/Vb5xxX8VZRI/AAAAAAAAACo/pnTUX_lqYA0/s1600/nolist.jpg>
>>>>
>>>> Hello I'm new to programming and web2py but here I'm doing my first
>>>> project.
>>>> I'm using web2py as a back-and for android app to get and transfer data.
>>>> I need to return list of user uploaded files( in JSON ) but web2py save
>>>> files with unique name.
>>>> I find most accurate solution to my problem:
>>>> http://stackoverflow.com/questions/8008213/web2py-upload-with-original-filename
>>>>
>>>> but it's not working for some reason
>>>> and some functions is not listed in "exposes:"(shwon in picture). why?
>>>>
>>>>
--
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/d/optout.