[web2py] Re: How to work with files in multipart/form-data?

2018-11-22 Thread Константин Комков
Val K, yes, you are right. I do like you told and now all work. Moreover I 
made conclusion of error and now it work right too, previosly I have had 
error only one of type.
Thank you!

-- 
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: How to work with files in multipart/form-data?

2018-11-21 Thread Val K
If want to validators do their stuff, just try   
db_app.doc_images.validate_and_insert(... , file=doc)

db_app.doc_images.file.store - just a helper that sanitizes the filename, 
adds a unique prefix and saves the file + returns its real (OS) name
So,  in your example, the  validation happens too late.












On Wednesday, November 21, 2018 at 12:29:07 PM UTC+3, Константин Комков 
wrote:
>
> loadDoc = db_app.doc_images.validate_and_insert(person='{0} {1} 
> {2}'.format(session.abit_f,session.abit_i,session.abit_o),file=db_app.doc_images.file.store(doc,doc.filename))
> I see another expansion in uploads yet. And loadDoc.errors.as_dict() 
> contain {'file','enter valid 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 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: How to work with files in multipart/form-data?

2018-11-21 Thread Константин Комков
loadDoc = db_app.doc_images.validate_and_insert(person='{0} {1} 
{2}'.format(session.abit_f,session.abit_i,session.abit_o),file=db_app.doc_images.file.store(doc,doc.filename))
I see another expansion yet. And loadDoc.errors.as_dict() contain 
{'file','enter valid 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 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: How to work with files in multipart/form-data?

2018-11-16 Thread Константин Комков

>
> how did they (.exe, .html ...) get there?

When I tested loading documents I heve tried to load test.html from site of 
course. After that I cheked table db_app.doc_images and there isn't record 
with that file and after that I cheked folder uploads and unfortunately 
found test.html.
>
> There is no any hard link between db and the folder 'uploads', you can 
> kill all files in the folder, but web2py will still think that they are in 
> it.

Of course I know it. It's logically.

> + read the book and feel the difference between just 'insert' and 
> 'validate_and_insert'

As I thought to write requires will be enought, like that:

Field 
('file',
 'upload',label='Документ', requires=[IS_UPLOAD_FILENAME 
(extension='^(pdf|tiff|png|bmp|jpeg|jpg)$'),IS_LENGTH
 (10485760, 1024)]),

That code worked with crud form and I couldn't load file test.html.


-- 
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: How to work with files in multipart/form-data?

2018-11-16 Thread Val K
how did they (.exe, .html ...) get there?
There is no any hard link between db and the folder 'uploads', you can kill 
all files in the folder, but web2py will still think that they are in it.
+ read the book and feel the difference between just 'insert' and 
'validate_and insert'



On Friday, November 16, 2018 at 4:16:18 PM UTC+3, Константин Комков wrote:
>
> I found one unpleasant mistake. In model:
>
> db_app.define_table('doc_images',
> Field 
> ('person',label='ФИО',writable=False),
> Field 
> ('file', 
> 'upload',label='Документ', requires=[IS_UPLOAD_FILENAME 
> (extension='^(pdf|tiff|png|bmp|jpeg|jpg)$'),IS_LENGTH
>  (10485760, 1024)]),
> format = '%(title)s')
>
>
> requires don't work for folder uploads. In ab_app.doc_images there are not 
> record with .exe, .html etcetra, but in uploads I can see files with any 
> expansion.
>

-- 
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: How to work with files in multipart/form-data?

2018-11-16 Thread Константин Комков
I found one unpleasant mistake. In model:

db_app.define_table('doc_images',
Field 
('person',label='ФИО',writable=False),
Field 
('file', 
'upload',label='Документ', requires=[IS_UPLOAD_FILENAME 
(extension='^(pdf|tiff|png|bmp|jpeg|jpg)$'),IS_LENGTH
 (10485760, 1024)]),
format = '%(title)s')


requires don't work for folder uploads. In ab_app.doc_images there are not 
record with .exe, .html etcetra, but in uploads I can see files with any 
expansion.

-- 
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: How to work with files in multipart/form-data?

2018-11-14 Thread Константин Комков
Val K, thank you! All work.
If somebody want to upload files using one button use it:
controller:
def loadDocs():
documents = request.vars
for key in documents:
doc = documents[key]
db_app.doc_images.insert(person='{0} {1} 
{2}'.format(session.abit_f,session.abit_i,session.abit_o),file=db_app.doc_images.file.store(doc,doc.filename))
return doc.filename
view:
Прикрепить


$(function() {
var files;
function showLoadDocsInfo(data) {
console.log('In showLoadDocsInfo');
console.log(data);
}
$('#openDialog').on('change', function () {
files = this.files;
console.log('files = '+files);
if (typeof files == 'undefined' ) return;
var data = new FormData();
$.each( files, function(key, value ) {
data.append(key, value);
});
console.log('data = '+data);
jQuery.ajax({
type: "POST",
url: "loadDocs",
data: data,
//enctype: 'multipart/form-data',
cache: false,
processData: false,
contentType: false,
success: showLoadDocsInfo,
error: function(data){
console.log("error");
console.log(data);
}
});
});
$('#btnOne').on('click', function() {
$('#openDialog').click();
});
});




-- 
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: How to work with files in multipart/form-data?

2018-11-14 Thread Val K
Well, it's strange ... web2py should read filename from passed doc, but it 
seems it does not do it. Try to pass doc.filename as second arg to .store()

-- 
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: How to work with files in multipart/form-data?

2018-11-14 Thread Константин Комков
Controller:
>
> def loadDocs():
> documents = request.vars
> for key in documents:
> doc = documents[key]
> db_app.doc_images.insert(person='{0} {1} 
> {2}'.format(session.abit_f,session.abit_i,session.abit_o),file=db_app.doc_images.file.store(doc))
> return doc.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 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: How to work with files in multipart/form-data?

2018-11-14 Thread Val K
Show controller code pls

-- 
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: How to work with files in multipart/form-data?

2018-11-14 Thread Константин Комков
doc.filename = flower.jpg
result file in uploads - doc_images.file.94aa36d88e4a9c73.4e6f6e65.txt
I want to get - doc_images.file.94aa36d88e4a9c73.4e6f6e65.jpg

-- 
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: How to work with files in multipart/form-data?

2018-11-14 Thread Val K
Check what does doc.filename look like

-- 
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: How to work with files in multipart/form-data?

2018-11-13 Thread Константин Комков
Val K, thank you! It's big progress.
I change in your code that string:

> data.append(key , value );

And I had error in that string:

> db_app.doc_images.insert(person='{0} {1} {2}'.format(session.abit_f,
> session.abit_i,session.abit_o),file=*db_app*.doc_images.file.store(doc))

I see file in uploads, but it is like text file, but I loaded jpg. 
When I changed .txt on .jpg I saw picture. What should I do for loading 
file with initial expansion?

-- 
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: How to work with files in multipart/form-data?

2018-11-13 Thread Val K
oops! `serialize` is really bad idea;)

this should work:
 $.each( files, function( key, value ) {
data.append( 'file_' + key , value ); //  because key = 0, 
1, 2 ... - or is that what you want? 
});

jQuery.ajax({
type: "POST",
url: "loadDocs",
data: data, // nothing else
cache: false,
processData: false,
contentType: false,
success: showLoadDocsInfo
});

def loadDocs():
documents = request.vars
for key in documents: # key = file_0, file_1 ...
doc = documents[key] #  - cgi.FieldStorage
db_app.doc_images.insert(person='{0} {1} 
{2}'.format(session.abit_f,session.abit_i,session.abit_o),file=db.doc_images.file.store(doc))
return images # - ???




On Tuesday, November 13, 2018 at 6:56:00 PM UTC+3, Константин Комков wrote:
>
> data: {data: JSON.stringify(...)}
>>
> not work
>
> As I understood serialize working only with form. I don't heve form ↑.  
> Can we use serialize for file?
>

-- 
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: How to work with files in multipart/form-data?

2018-11-13 Thread Константин Комков

>
> data: {data: JSON.stringify(...)}
>
not work

As I understood serialize working only with form. I don't heve form ↑.  Can 
we use serialize for file?

-- 
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: How to work with files in multipart/form-data?

2018-11-12 Thread Val K
Try in ajax
data: {data: JSON.stringify(...)}

-- 
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: How to work with files in multipart/form-data?

2018-11-12 Thread Константин Комков
Hello, help me please. I don't know what I need to do on server in 
controller
def loadDocs():
documents = request.vars.data
for i in documents:
stream = open(i.file, 'rb')
db_app.doc_images.insert(person='{0} {1} 
{2}'.format(session.abit_f,session.abit_i,session.abit_o),file=db.doc_images.file.store(stream,
 
i.file))
return images
Why is variable documents equal None?
Error: ('NoneType' object is not iterable)

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