Re: [web2py] Re: uploadfolder outside web2py

2018-01-17 Thread Richard Vézina
Symlink is another option... I had use symlink for a while for uploads
files as I was storing them on another system, so they were backuped and
reduced the size of my linux box... I stop doing it because there network
latency and the mount point was often down. But it works very well...

Richard

On Wed, Jan 17, 2018 at 11:12 AM, 'Annet' via web2py-users <
web2py@googlegroups.com> wrote:

> Hi Anthony,
>
> Thanks for helping me solve the issue, I very much appreciate your help.
>
>
> @richard.
>
> Thanks for your reply, I had a look at bindfs, I work with Linux and had a
> symbolic link on myapp/static/uploads I am not sure bindfs let me upload
> files to myapp/static/uploads and store them in a directory structure
> outside web2py.
>
>
> Kind regards,
>
> Annet
>
>
> --
> 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.
>

-- 
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.


[web2py] Re: uploadfolder outside web2py

2018-01-17 Thread 'Annet' via web2py-users
Hi Anthony,

Thanks for helping me solve the issue, I very much appreciate your help.


@richard.

Thanks for your reply, I had a look at bindfs, I work with Linux and had a
symbolic link on myapp/static/uploads I am not sure bindfs let me upload
files to myapp/static/uploads and store them in a directory structure
outside web2py.


Kind regards,

Annet


-- 
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.


Re: [web2py] Re: uploadfolder outside web2py

2018-01-16 Thread Richard Vézina
You can also mount the directory you want you file in into web2py folder
with bindfs...

Or saying it differently mount a directory to another location...

https://bindfs.org/

But I think it would be only working with linux.

Good luck

Richard



On Mon, Jan 15, 2018 at 11:22 AM, Anthony  wrote:

> First, consider whether you really need a separate upload folder for each
> vertexID. The DAL already generates a unique filename for each upload, and
> the filename is stored in the database record, so you can always find the
> file by looking up the record.
>
> If you need the separate folders, though, consider setting the upload
> folder with the model definition so you don't need to specify it separately
> in the SQLFORM action and so it will be easier to make use of the built-in
> response.download function:
>
> IMAGE_FOLDER = os.path.join('/', 'Users', 'me', 'Documents')
>
> db.define_table('mytable',
> Field('image', 'upload', uploadfolder=os.path.join(IMAGE_FOLDER,
> 'vertexID%s' % session.vertexID),
> ...)
>
> Note, the folder path will end with "vertexIDNone" when there is no
> session.vertexID, but presumably that will not be an issue, as you should
> not be doing any uploads/downloads when there is no session.vertexID.
>
> With the above change, you can then change the download function to the
> standard:
>
> def download():
> return response.download(request, db)
>
> Anthony
>
> On Monday, January 15, 2018 at 4:41:58 AM UTC-5, Annet wrote:
>>
>> Hi Anthony,
>>
>> Thanks for your reply.
>>
>> After reading the parts on download() in chapter 7 and 9 I wrote the
>> following functions
>> to run locally:
>>
>> def logo():
>> vertexID = session.vertexID
>>
>> table.vertexID.default = vertexID
>> folder = 'vertexID' + str(vertexID)
>> table.image.uploadfolder = os.path.join('/Users/me/Documents/' +
>> folder)
>>
>> record = table(vertexID=vertexID)
>>
>> form = SQLFORM(table, record, deletable=True, showid=False,
>>upload=URL('image_download', args=request.vars.image))
>>
>> if form.process().accepted:
>> if record and form.vars.image__delete:
>> file = record.image
>> os.remove(os.path.join('/Users/me/Documents/' + folder,
>> file))
>> elif form.errors:
>> get_flash(response, None, 'danger', 'error')
>> elif not response.flash:
>> get_flash(response, None, 'info', 'custom')
>>
>> return dict(form=form)
>>
>> def image_download():
>> folder = 'vertexID' + str(session.vertexID)
>> file_path = os.path.join('/Users/me/Documents/' + folder + '/')
>> return response.stream(open(file_path + request.args(0)))
>>
>>
>> Are there any improvements to make to this code?
>>
>>
>> Kind regards,
>>
>> Annet
>>
>> --
> 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.
>

-- 
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.


[web2py] Re: uploadfolder outside web2py

2018-01-15 Thread Anthony
First, consider whether you really need a separate upload folder for each 
vertexID. The DAL already generates a unique filename for each upload, and 
the filename is stored in the database record, so you can always find the 
file by looking up the record.

If you need the separate folders, though, consider setting the upload 
folder with the model definition so you don't need to specify it separately 
in the SQLFORM action and so it will be easier to make use of the built-in 
response.download function:

IMAGE_FOLDER = os.path.join('/', 'Users', 'me', 'Documents')

db.define_table('mytable',
Field('image', 'upload', uploadfolder=os.path.join(IMAGE_FOLDER, 
'vertexID%s' % session.vertexID),
...)

Note, the folder path will end with "vertexIDNone" when there is no 
session.vertexID, but presumably that will not be an issue, as you should 
not be doing any uploads/downloads when there is no session.vertexID.

With the above change, you can then change the download function to the 
standard:

def download():
return response.download(request, db)

Anthony

On Monday, January 15, 2018 at 4:41:58 AM UTC-5, Annet wrote:
>
> Hi Anthony,
>
> Thanks for your reply.
>
> After reading the parts on download() in chapter 7 and 9 I wrote the 
> following functions
> to run locally:
>
> def logo():
> vertexID = session.vertexID
>
> table.vertexID.default = vertexID
> folder = 'vertexID' + str(vertexID)
> table.image.uploadfolder = os.path.join('/Users/me/Documents/' + 
> folder)
>
> record = table(vertexID=vertexID)
>
> form = SQLFORM(table, record, deletable=True, showid=False,
>upload=URL('image_download', args=request.vars.image))
>
> if form.process().accepted:
> if record and form.vars.image__delete:
> file = record.image
> os.remove(os.path.join('/Users/me/Documents/' + folder, file))
> elif form.errors:
> get_flash(response, None, 'danger', 'error')
> elif not response.flash:
> get_flash(response, None, 'info', 'custom')
>
> return dict(form=form)
>
> def image_download():
> folder = 'vertexID' + str(session.vertexID)
> file_path = os.path.join('/Users/me/Documents/' + folder + '/')
> return response.stream(open(file_path + request.args(0)))
>
>
> Are there any improvements to make to this code?
>
>
> Kind regards,
>
> Annet
>
>

-- 
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.


[web2py] Re: uploadfolder outside web2py

2018-01-15 Thread 'Annet' via web2py-users
Hi Anthony,

Thanks for your reply.

After reading the parts on download() in chapter 7 and 9 I wrote the 
following functions:

def logo():
vertexID = session.vertexID

table.vertexID.default = vertexID
folder = 'vertexID' + str(vertexID)
table.image.uploadfolder = os.path.join('/Users/iannet/Documents/' + 
folder)

record = table(vertexID=vertexID)

form = SQLFORM(table, record, deletable=True, showid=False,
   upload=URL('image_download', args=request.vars.image))

if form.process().accepted:
if record and form.vars.image__delete:
file = record.image
os.remove(os.path.join('/Users/iannet/Documents/' + folder, 
file))
elif form.errors:
get_flash(response, None, 'danger', 'error')
elif not response.flash:
get_flash(response, None, 'info', 'custom')

return dict(form=form)

def image_download():
folder = 'vertexID' + str(session.vertexID)
file_path = os.path.join('/Users/iannet/Documents/' + folder + '/')
return response.stream(open(file_path + request.args(0)))


Are there any improvements to make to this code?


Kind regards,

Annet

-- 
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.


[web2py] Re: uploadfolder outside web2py

2018-01-14 Thread Anthony
On Sunday, January 14, 2018 at 4:30:57 AM UTC-5, Annet wrote:
>
> Thank you all for your replies,
>
> This works :
>
> table.image.uploadfolder = '/home/webapps/uploads'
>
> to upload the images into separate folders I made the following adjustment:
>
> folder = 'vertexID' + str(vertexID)
> table.image.uploadfolder = os.path.join('/home/webapps/uploads/' + folder)
>
>
> The problem is the image file doesn't display in the form:
>
> form = SQLFORM(table, record, deletable=True, showid=False,
>upload=URL('home', 'webapps', 'uploads/' + folder, 
> args=request.vars.image))
>

web2py does not serve files by simply passing a filesystem path as a URL. 
If you are not storing the files in the application's /static folder, you 
must create an action within your app that serves uploaded files (see the 
/default/download action in the welcome app for an example) and specify the 
URL of that action as the "upload" argument.

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.


[web2py] Re: uploadfolder outside web2py

2018-01-14 Thread 'Annet' via web2py-users
Thank you all for your replies,

This works :

table.image.uploadfolder = '/home/webapps/uploads'

to upload the images into separate folders I made the following adjustment:

folder = 'vertexID' + str(vertexID)
table.image.uploadfolder = os.path.join('/home/webapps/uploads/' + folder)


The problem is the image file doesn't display in the form:

form = SQLFORM(table, record, deletable=True, showid=False,
   upload=URL('home', 'webapps', 'uploads/' + folder, 
args=request.vars.image)) 


This buils the following source:

scr="/home/webapps/uploads/vertexID1/img_logo.image.bbaf6c..6e67.png"

Why doesn't the image file display in the form?

Also when I check the check to delete checkbox and submit the form the image
file isn't deleted.


Kind regards,

Annet

-- 
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.


[web2py] Re: uploadfolder outside web2py

2018-01-12 Thread Anthony
On Friday, January 12, 2018 at 5:18:30 AM UTC-5, 黄祥 wrote:
>
> pls try:
> table.image.uploadfolder = os.path.join(request.folder, '..', '..', '..', 
> 'webapps', 'uploads')
>

Also, unless it needs to be portable to other filesystems where the path 
does not start with "/home", you can simplify to:

table.image.uploadfolder = os.path.join('/', 'home', 'webapps', 'uploads')

or even just:

table.image.uploadfolder = '/home/webapps/uploads'

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.


[web2py] Re: uploadfolder outside web2py

2018-01-12 Thread Dave S


On Friday, January 12, 2018 at 12:07:22 AM UTC-8, Annet wrote:
>
> In web2py I have an init application and an adminmod application 
> containing the model, module and static files.
>
> To manage images I have the following code in a function:
>
>
> table.image.uploadfolder = os.path.join(request.env.applications_parent, 
> 'applications',
> 'adminmod', 'static/uploads', 
> folder)
>
> form = SQLFORM(table, record, deletable=True, showid=False,
>upload=URL('adminmod', 'static/uploads', folder, 
> args=request.vars.image))
> if hasattr(request.vars.image, 'filename'):
> form.vars.imageFilename = request.vars.image.filename
>
> if form.process().accepted:
> if record and form.vars.image__delete:
> file = record.image
> os.remove(os.path.join(request.env.applications_parent, 
> 'applications',
>'adminmod', 'static/uploads', folder, 
> file))
>
>
> In production I have a symbolic link application referenced by a 
> subdomain: images.mydomain.com
>
>
> In the init application images have the following source selector:
>
>  alt="" />
>
>
> Is it possible to upload the image to an uploadfolder outside web2py, so 
> instead to this folder:
>
> /home/username/webapps/w2p/web2py/applications/adminmod/static/uploads
>
> to this folder:
>
> /home/username/webapps/uploads
>
>
> Kind regards,
>
> Annet
>
>

In addition to Stifan's remarks, I can attest that web2py can easily serve 
files outside of the web2py tree, although in my case those files aren't an 
upload field.

See also

(there are several parameters related to uploads), and also


/dps

S 

-- 
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.


[web2py] Re: uploadfolder outside web2py

2018-01-12 Thread 黄祥
pls try:
table.image.uploadfolder = os.path.join(request.folder, '..', '..', '..', 
'webapps', 'uploads')

assuming there are folders:
/home/web2py/applications/adminmod
/home/webapps/uploads

according to your path, i think it just a little adjustment of parent 
folder ,'..', '..'

best regards,
stifan

-- 
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.