# Model
db.define_table('my_uploads',
Field('upload_field', 'upload')
)
# Controller
def upload():
""" Store the upload and return an URL to see the new file """
stored_name = db.my_uploads.upload_field.store(request.vars['file[]']) # Note that Field.store works fine with cgi.FieldStorage
db.my_uploads.insert(upload_field=stored_name)
return URL('default', 'download', args=stored_name, scheme=True, host=True)
Hi and thanks :)Ill try that later. But I need to keep the image outside of the db (not in a blob field), and only keep a reference to the location of the image on the disk. I am going to run a python script on the image I am uploading to do OCR analysis triggered by the Scheduler, so I need the image on the disk. How can I move the image to somewhere on the disk instead of saving it in the db?Cheers
On Monday, March 13, 2017 at 12:10:32 PM UTC-7, Mika Sjöman wrote:Hi and thanks :)Ill try that later. But I need to keep the image outside of the db (not in a blob field), and only keep a reference to the location of the image on the disk. I am going to run a python script on the image I am uploading to do OCR analysis triggered by the Scheduler, so I need the image on the disk. How can I move the image to somewhere on the disk instead of saving it in the db?Cheers
We may need to know more about your React Native tool.
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7yCg0huUwXE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sorry I assumed you wanted it in the DB you don't want it in the DB. You can just manipulate the file directly and save it whoever you want, you have a cgi.FieldStorage in request.vars['file[]'] you can use it to access the uploaded file.
up_file = request.vars['file[]']up_file.file # will have a file object you can use to read the data and write it to diskup_file.filename # wil have the uploaded file filename
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/7yCg0huUwXE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I tried that (up_file = request.vars['file[]']), but I still just get the String printed out in my console:"FieldStorage('file[]', 'mikasworld.jpg', '\xff\...base64 representation of the image.
The strange thing is that the upload seems to go all right, but it never saves the file. If I remember right, uploaded files just appears in the /upload folder once complete, but this doesn't happen here. Strange....
I am getting this ouput in my console, so for sure it upload the file and given the request.vars response, it seems like the server is accepting the upload but not saving the file. This is my output during the upload:upload progress: 19.57139819860458%ImageViewer.js:75 upload progress: 39.14279639720917%ImageViewer.js:75 upload progress: 58.71419310569763%ImageViewer.js:75 upload progress: 78.28559279441833%ImageViewer.js:75 upload progress: 97.85698652267456%ImageViewer.js:75 upload progress: 100%Any ideas on why I get a FieldStorage object but not a saved file to disk on the server? Is there any step I need to take after the file has been uploaded that finally saves the file to disk?
On Mon, Mar 13, 2017 at 9:23 PM, Leonel Câmara <leonel...@gmail.com> wrote:
Sorry I assumed you wanted it in the DB you don't want it in the DB. You can just manipulate the file directly and save it whoever you want, you have a cgi.FieldStorage in request.vars['file[]'] you can use it to access the uploaded file.up_file = request.vars['file[]']up_file.file # will have a file object you can use to read the data and write it to diskup_file.filename # wil have the uploaded file filename
[...]
----Mvh/Sincerely yoursMika Sjöman
--
Yes I did both but I kept getting the same output no matter what I did.//Cheers
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
On Monday, March 13, 2017 at 10:56:49 PM UTC-7, Mika Sjöman wrote:Yes I did both but I kept getting the same output no matter what I did.//Cheers
I think you need to copy the field store to a file. That is, you do a normal python open for a file that's going to be where you want it, and it's write method needs to suck stuff out of the field store. I don't know enough about the latter to know if that's store.stream() or store.read().
After the store has been poured into the file, close the file.
/dps
if fileitem.file:
linecount = 0
while 1:
line = fileitem.file.readline()
if not line: break
linecount = linecount + 1