How to refer uploads files

51 views
Skip to first unread message

Chaitu P

unread,
Jun 25, 2015, 4:17:13 AM6/25/15
to web...@googlegroups.com
I want to compile the files that were uploaded. But the files are getting uploaded with some random name. So how can I refer them.

Massimo Di Pierro

unread,
Jun 25, 2015, 4:52:32 AM6/25/15
to web...@googlegroups.com, chaitanya....@gmail.com
Do not understand the question.

Mandar Vaze

unread,
Jun 25, 2015, 2:16:35 PM6/25/15
to web...@googlegroups.com

On Thursday, June 25, 2015 at 1:47:13 PM UTC+5:30, Chaitu P wrote:
I want to compile the files that were uploaded. But the files are getting uploaded with some random name. So how can I refer them.

Filenames under uploads folder are purposely mangled (what you call random names) for security reasons.
What you want to do is unclear though 
Do you want to list all the "actual" filenames under uploads folder?

-Mandar

Anthony

unread,
Jun 25, 2015, 3:01:21 PM6/25/15
to web...@googlegroups.com, chaitanya....@gmail.com
The original filename is encoded in the new filename. However, if you need easier access to the original filename (without bothering with the decoding), you can store the original filename in a separate field. For details, see http://www.web2py.com/books/default/chapter/29/07/forms-and-validators#Storing-the-original-filename.

Anthony

Manuele Pesenti

unread,
Jun 26, 2015, 4:19:49 AM6/26/15
to web...@googlegroups.com
Il 24/06/15 21:23, Chaitu P ha scritto:
> I want to compile the files that were uploaded. But the files are
> getting uploaded with some random name. So how can I refer them.
Please give more ditails of what you are trying to do... I guess you are
using a "no dal" form to upload your files... right?

M.

Chaitu P

unread,
Jun 30, 2015, 3:30:28 AM6/30/15
to web...@googlegroups.com
I have form where student can upload his c programs. Now I want to write a script which will compile and run these programs.
I was able to write a script which can compile and run c programs with simple name like hello.c. But the problem is Iam not sure how can I refer the files that were saved with random names in uploads folder, for execution.

Here is my code.


import time
import subprocess
while True:
rows = db(db.student.status=='pending').select()
ofile = open('C:\\web2py\\applications\\newdropboxmultiupload\\cache\\temp\\hellonewtest.out', 'w')
for row in rows:
#subprocess.call(["gcc","C:\web2py\hello.c","-o","x"])
subprocess.call(["./x"], stdout=ofile)
row.update_record(status='executed')
db.commit()
time.sleep(60) # check every minute
ofile.close()

Chaitu P

unread,
Jun 30, 2015, 3:30:28 AM6/30/15
to web...@googlegroups.com
I have a form where student can submit his .c programs. Now I want to write a script that run these programs. I was able compile and run c programs with a python scripts with normal name like hello.c. But Iam not sure how can refer these programs that were saved with random name. Here is my script.


## in file /app/private/mail_queue.py
import time
import subprocess
while True:
rows = db(db.student.status=='pending').select()
ofile = open('C:\\web2py\\applications\\newdropboxmultiupload\\cache\\temp\\hellonewtest.out', 'w')
for row in rows:
subprocess.call(["gcc","C:\web2py\hello.c","-o","x"])
subprocess.call(["./x"], stdout=ofile)
row.update_record(status='executed')
db.commit()
time.sleep(60) # check every minute
ofile.close()


    M.

--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Chaitanya Pochampally

Anthony

unread,
Jun 30, 2015, 10:28:16 AM6/30/15
to web...@googlegroups.com, chaitanya....@gmail.com
When you create an upload field using the DAL, the filename is stored in the upload field itself, so you can get the filepath via:

import os
filepath
= os.path.join(request.folder, 'uploads', row.upload_field_name)

The above assumes all uploads go directly in the /uploads folder. If you have specified an alternative upload folder, you will need to use that instead of "uploads" (also, if you set uploadseparate=True, that will take some extra work to get the full path).

Anthony
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Chaitanya Pochampally
Reply all
Reply to author
Forward
0 new messages