Should be URL('static','images/files/{*0*}'.format(file[1]))
Richard
On Thu, Mar 31, 2016 at 6:34 AM, Marko Seppälä <[email protected]> wrote:
> Hi,
>
> I want to upload some of the images programmatically from file system,
> when initializing the database. Not the actual file though, just normal
> upload so that file stays in file system but it's accessible via database
> for every user.
>
> I tried something like this:
>
> db.define_table('image',
> Field('name'),
> Field('file', 'upload')
> )
>
> FILES = [
> ['apple', 'apple.png'],
> ['dog', 'gog-image.png'],
> ...
> ]
>
> if db(db.image.id>0).count() == 0:
> for file in FILES:
> filename = URL('static','images/files/{}'.format(file[1]))
> stream = open(filename, 'rb')
> db.image.insert(name=file[0], file=stream)
>
> I'll get an error:
> * <type 'exceptions.IOError'> [Errno 2] No such file or directory:
> '/example/static/images/files/apple.png'*
>
> It looks like my path is broken and I should use os.path.join etc. to get
> the whole path. But I couldn't make this work.
> What is the correct way to set that path? For example, how it is done by
> web2py since everything works normally if I upload those images via admin
> interface? I'm working on Windows environment.
>
> --
> 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.
>
--
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.