Upload de arquivos no Plone
Voltar para o PortalExistem atualmente 3 resposta(s) ao tópico
This discussion is threaded
Re: Upload de arquivos no Plone
por Davi Lima
—
created
07/06/2008 17:53
PYTHON SCRIPT
from Products.PythonScripts.standard import html_quote
from Products.CMFCore.utils import getToolByName
request = container.REQUEST
RESPONSE = request.RESPONSE
file = request.get('file',None)
filename = file.filename
folder = getattr(context, context.id)
if str(filename) in folder.objectIds():
print 'arquivo existe'
else:
try:
folder.manage_addProduct['OFSP'].manage_addFile(filename, file)
except:
print 'Erro ao tentar efetuar o upload'
else:
return RESPONSE.redirect(context.id)
return printed
PAGE TEMPLATE
<html>
<head>
<title tal:content="template/title">The title</title>
</head>
<body>
<fieldset>
<legend tal:content="template/title|nothing">titulo</legend>
<form action="save_file" method="post" enctype="multipart/form-data">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td align="left" valign="top">
<div class="form-optional">
File
</div>
</td>
<td align="left" valign="top">
<input type="file" name="file" size="25" value="" />
</td>
</tr>
<tr>
<td align="left" valign="top"></td>
<td align="left" valign="top">
<div class="form-element">
<input class="form-element" type="submit" name="submit" value=" Add " />
</div>
</td>
</tr>
</table>
</form>
</fieldset>
<tal:block tal:define="filesup python:context.objectValues(['File','Image'])">
<fieldset tal:condition="filesup">
<legend>Arquivos adicionados</legend>
<ul>
<li tal:repeat="itens filesup">
<span tal:content="python:DateTime(itens.bobobase_modification_time()).strftime('%d-%m-%Y - ')"></span>
<a tal:attributes="href string:${here/absolute_url}/${itens/id}" tal:content="python:'%s' %(itens.title_or_id())">arquivo</a>
<span style="color:red" tal:condition="python:itens.getSize() < 1024">1 MB</span>
<span style="color:red" tal:condition="python:itens.getSize() > 1048576" tal:content="python:'%0.02f MB' %(itens.getSize() / 1048576.0)"></span>
</li>
</ul>
</fieldset>
</tal:block>
</body>
</html>
Re: Re: Upload de arquivos no Plone
por Pedro Vítor L. Rodrigues
—
created
16/06/2008 16:42
Davi, só para constar...
Você salvou minha vida. Muito obrigado xD
Re: Re: Upload de arquivos no Plone
por Guilherme Lopes
—
created
25/06/2008 13:38
Aew Davi,
Me responde uma coisa!?
Com esse codigo ae qual seria o erro que o try: pegaria ali no momento que ele faz isso
try:
folder.manage_addProduct['OFSP'].manage_addFile(filename, file)
except:
print 'Erro ao tentar efetuar o upload'
Pois fiz um codigo semelhante ao seu mas infelizmente meus arquivos so caem nesse caso!?
Seria alguma restrição ao tamanho do arquivo...algo do tipo!!?
att.
Guilherme Lopes
Pessoal,
estou precisando desenvolver um form no plone onde, através de um input="file",
o usuario selecione um arquivo e este seja carregado para o
servidor (upload) e entao
1 - copiado para uma pasta chamada "bi-atual"
2 - renomeado para "arq.pdf"
3 - copiado para a pasta "bis"
O problema está em como fazer um upload de arquivos na mão...
Tentei fazer usando um script python para processar mas não consegui.
Estou precisando disso com urgência, alguem poderia me ajudar por favor?
Desde já agradeço.