On Friday, June 9, 2017 at 10:03:57 AM UTC-7, Maurice Ling wrote:
>
> Thanks for your reply, Dave.
>
> However, I don't really get the part on "drag and drop" - do you mean drag 
> and drop the file into the field? Will it work for a text area?
>

It works with an upload field, which is what you need for uploading a 
file.  Part of the story is HTML5, and part is javascript, but it already 
works in web2py with all modern browsers.  The app that expects pictures is 
at home, so I can't look at thumbnails, but I just tested it with another 
app here.  Client was W10 (but should be able to go back to at least XP), 
Firefox 53.0.3, but should work back into the 30s.  To do the test, I 
opened the page with form, switched windows to WinExplorer to select a 
file, left-clicked on the one I chose, and dragged it over the "Browse..." 
button for the upload field.

On  the server side, I log the upload activity (beyond what Rocket puts 
into httpserver.log) which at the moment includes the size of the file and 
the id of upload table row.

/dps

 

> On Friday, 26 May 2017 02:55:50 UTC+8, Dave S wrote:
>>
>>
>>
>> On Thursday, May 25, 2017 at 8:34:44 AM UTC-7, Maurice Ling wrote:
>>>
>>> Hi everyone,
>>>
>>> I am stuck with an issue - please refer to the code below.
>>>
>>> [...]
>>>
>> 5. I will the want to copy the file into application/<app name>/upload 
>>> folder using shutils (lines 17-25) but the file name will be changed to 
>>> entry.file.<random number>.<original file name>
>>> 6. However, this does not work as I get the error that the file is not 
>>> found. 
>>> 7. For debugging, I print the source file name (line 21) and it only 
>>> gave me the file name when I will need the entire file path for 
>>> shutil.copy2() at line 25 to work.
>>> *[...]* 
>>>
>>                sourcefile = form.vars.uploadfile.filename
>>>
>>
>>>    1.                 print sourcefile
>>>    2.                 newfile = upload_dir + os.sep + 'entry.file.' + \
>>>    3.                         str(int(random.random()*10000000000000)) 
>>>    + \
>>>    4.                         os.path.splitext(sourcefile)[-1]
>>>    5.                 shutil.copy2(sourcefile, newfile)
>>>    6. 
>>>
>>> [...]
>>>
>>  
>> A browser won't tell you the path to the file, just the filename.  It's a 
>> security measure.  The shutil.copy2() call can only handle files local to 
>> the server.  If you're using this page locally on the server, then you can 
>> provide the path information through other channels.
>>
>> I do something like this on my home machine, because I'm using my app to 
>> tag my photos.   Currently, I provide a text field on the form to enter 
>> path (separate from filename), but I check that path against a list I keep 
>> in the code.  That limits the amount filesystem exploration someone could 
>> do if they somehow got access to my app.
>> (BTW, drag-and-drop works for getting the filename into its field).
>>
>> /dps
>>
>>
>>

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

Reply via email to