I'm returning for feedback. I changed the controller, so I will not be using generic pattern, correct? Another problem solved was that the pillow, strangely, was not processing the sent image. I uninstalled and reinstalled again so far everything is fine. Here's the change (red):
Thanks Leonel Câmara and Anthony. đ *in models:* pasta_upload=os.path.join(request.folder, 'uploads') if auth.user: pasta_upload=os.path.join(request.folder, 'uploads', auth.user.email) if not os.path.exists(pasta_upload): os.makedirs(pasta_upload) db.define_table('imagens', Field('imagem', 'upload', autodelete=True, uploadfolder=pasta_upload), auth.signature ) *on controller:* #@Auth_phanterimages.requires(Auth_phanterimages.has_membership(role="uploader"), requires_login=True) def upload_imagens(): html=DIV(H1("Escolha suas imagens"), FORM(INPUT(_name='imagem', _multiple='', _accept="image/png, image/jpeg, image/gif, image/bmp", _type='file', _id='no_table_imagem', _class="upload input-file"), _id="profile"), DIV(BUTTON("Enviar", _id="send")), DIV( DIV(DIV(_class="progress-bar progress-bar-striped active", _style="width: 0%"), _class="barra_progresso") ), DIV(_class='imagens_uplodeadas'), _class='upload_imagens') return locals() #@Auth_phanterimages.requires(Auth_phanterimages.has_membership(role="uploader"), requires_login=True) def echo_upload(): *import json* import os nomeArquivoExt = request.vars.fileToUpload.filename nomeArquivo, Ext = os.path.splitext(nomeArquivoExt) if Ext in ['.png', '.jpg', '.gif', '.jpeg', '.PNG', '.JPG', '.GIF', '.JPEG']: file = request.vars.fileToUpload.file id_upload=db_phanterimages.imagens.insert(imagem=db_ phanterimages.imagens.imagem.store(request.vars.fileToUpload.file, nomeArquivoExt)) q_imagem=db_phanterimages(db_phanterimages.imagens.id==id_ upload).select().first() * return json.dumps(dict(result=URL('**phanterimages', 'download', args=[q_imagem.imagem], extension=False)))* else: *return json.dumps(dict(result=URL('static', 'images', args=['nao_eh_imagem.jpg'])))* *on view:* {{extend 'layout.html'}} {{=html}} {{block page_js}} <script> var valor=0 $(document).ready(function (){ $("#send").on("click", function (){ valor=0 $('.progress').fadeIn(); blob = $("#no_table_imagem")[0].files; var quantidade_arq=blob.length var porcents = 100/quantidade_arq for (var i = quantidade_arq - 1; i >= 0; i--) { var tipo = blob[i]['type'] var nome_img= blob[i]['name'] if (tipo=="image/png"||tipo=="image/bmp"||tipo=="image/gif"| |tipo=="image/jpeg"){ uploadFile($("#profile")[0], blob[i], nome_img, porcents); } else{ alert("NĂŁo foi possĂvel fazer o upload do arquivo "+nome_img) } } }); }); function uploadFile(form, blobFile, fileName, porcents) { var fd = new FormData(); valor+=porcents fd.append("fileToUpload", blobFile); $.ajax({ url: "{{=URL(f='echo_upload.json')}}", type: "POST", data: fd, processData: false, contentType: false, async: true, success: function(response) { $('.progress-bar').css('width', valor+"%") console.log(response['result']) $('.imagens_uplodeadas').append("<img src='"+response['result']+"'>") }, error: function(jqXHR, textStatus, errorMessage) { console.log(errorMessage); } }); } </script> {{end page_js}} 2017-07-16 12:13 GMT-03:00 Anthony <abasta...@gmail.com>: > On Sunday, July 16, 2017 at 7:20:33 AM UTC-4, Leonel Câmara wrote: > > You are using the generic json view. By default generic views are only > allowed on localhost. You need to allow it for your function by adding > something like this to your models. > > > > > > response.generic_patterns = ['default/echo_upload.json'] > > generic_patterns should match the names of the generic templates, not the > names of functions that lack a dedicated template. Just matching to 'json' > should do, but this line should go in the controller function so it doesn't > affect other requests. > > Anthony > > -- > 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. > -- 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.