On Friday, April 28, 2017 at 11:52:53 AM UTC-7, [email protected] 
wrote:
>
> hi,
>
> I want save one image in dinamic directory  web2py, but ai not using 
> SQLFORM, 
>
> When i do upload the image i recieve in controller C:/FAKEPATH/imagename
>
> how do i handle this path or other upload ?
>

I'm not sure what your path represents ... is it the value sent to you by 
the browser
(in my experience, the "C:/SOMEPATH/" part isn't sent, and isn't even 
easily visible in javascript)
or is it where the file ends up on your server?

If it is where the file ends up, you can move the file via your controller 
function.  You need to import 'os' and 'os.path' to do the system calls for 
that.  Depending on which front end you use (apache, nginx, etc) you may 
have other options to control where the file initially lands.

The default in web2py is to configure a field in a table in your models as 
an 'upload' field; forms made with web2py helpers like FORM and SQLFORM 
will then put the file in your application/uploads directory.

 

> sorry my inglish.
>
>
If OUR English is hard for you to understand, you can still get help. We 
have some other Brazilian contributors, and I think the Brazilian forum is 
one of the larger subgroups
(evidenced from some cross-posting)
 
<URL:https://groups.google.com/forum/?fromgroups#!forum/web2py-users-brazil>

look my code:
>
>
I'm going to have to look at it more than once to follow.  The more 
experienced contributors might spot stuff faster than I can; my eyes are 
used to some of the web2py shortcuts.


/dps

 

> View:
>
> <form id="insertuser" novalidate>
>  <div class="col-md-12 col-sm-12 col-xs-12">
>   <div class="col-md-3 col-sm-12 col-xs-12">
>     <div class="form-group">
>   <label for="cadfirstname">Primeiro Nome</label>
>   <input type="text" class="form-control " id="cadfirstname" 
> placeholder="Primeiro Nome">
>                        
>     </div>
>    </div>
>    <div class="col-md-3 col-sm-12 col-xs-12">
>     <div class="form-group">
> <label for="cadsecondname">Segundo Nome</label>
> <input type="text" class="form-control " id="cadsecondname" 
> placeholder="Segundo Nome">
>     </div>
>   </div>
>    <div class="col-md-3 col-sm-12 col-xs-12" >
>     <div class="form-group">
> <label for="cademail">E-mail</label>
> <input type="email" class="form-control " id="cademail" 
> placeholder="Email" required="required" >
>     </div> 
>   </div>
>    <div class="col-md-3 col-sm-12 col-xs-12">
>     <div class="form-group">
> <label for="cadpass">Senha</label>
> <input type="password" class="form-control " id="cadpassuser" 
> placeholder="Senha">
>     </div> 
>    </div>
>  </div>
>  <br />
>  <div class="col-md-12 col-sm-12 col-xs-12">
>   <input id="image_title" name="text" type="text" /> 
>   <input id="image_file" name="file" type="file" /> 
>   <div class="form-group">
>   <button id="btn-user" type="button" class="btn btn-lg btn-primary fa 
> fa-floppy-o pull-right"> Cadastrar</button>
>    <button id="btn-limpar" type="reset" class="btn btn-lg btn-primary fa 
> fa-eraser pull-right" arial-hidden="true">  Limpar</button>
>   </div>
>  </div>
>
>
> <!-- AJAX -->
>
>
> $("#btn-user").click(function () {
> //ADD show Modal de loading 
> //$("#loading").modal('show');
> $("#loading").removeClass('hide') 
> var firstname = $('#cadfirstname').val();
> var lastname = $('#cadsecondname').val();
> var email = $('#cademail').val();
> var passuser = $('#cadpassuser').val();
> var image = $('#image_file').val();
>
> alert(form_vars);
> $.getJSON("{{=URL(c='manager', 
> f='newuser.json')}}",{firstname,lastname,email,passuser,image}, 
>  function(result){
> atualizaGrid();
> $("#retorno").removeClass('hide');
>                               
> //Atualiza combobox
> atualizaCombobox();
> //RESETAR FORMULARIO AO INSERIR
> $('#insertuser').each (function(){
>   this.reset();
> });
>
> //$("#loading").modal('hide');
> $("#loading").addClass('hide')                             
>  });   
>
> });
>
>
> CONTROLLER:
>
> @auth.requires_login()
> def newuser(): 
>   import json 
>   import gluon.contrib.simplejson
>   
>   #parametros de entrada da grid
>   firstname = request.vars['firstname']
>   lastname = request.vars['lastname']
>   email = request.vars['email']
>   passuser = request.vars['passuser']
>   image = request.vars['image']
>   
>   # Query
>   db.auth_user.insert(first_name=firstname, last_name=lastname, 
> email=email, password = db.auth_user.password.validate(passuser)[0] , image 
> = image, emp_id = db.auth_user[auth.user_id].emp_id)
>   
>   userid = db(db.auth_user).select(db.auth_user.id).last()
>
>   db.auth_membership.insert(user_id=userid,group_id=3)
>   
>   
>   data =  db(db.auth_user).select(db.auth_user.id,db.auth_user.first_name, 
> db.auth_user.last_name,db.auth_user.email,Link.id,CentroC.nome
> ,left=[Link.on(Link.userid == db.auth_user.id), CentroC.on(CentroC.id == 
> Link.centroid) ])
>   
>   code = response.session_id
>   message = response.status
>  
>   #retorno de variaveis grid   
>   return dict(code=code,message=message,data=data) 
>  
>
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to