Erro repentino em upload de arquivos (sem uso de componentes de terce
Caso já exista algum tópico relacionado ao assunto peço que me desculpem mas não o encontrei.
Estou com um problema grave no upload de arquivos em todos os sites que implementamos na empresa.
Tudo funcionava as mil maravilhas até que de ontem para hoje simplesmente não consigo fazer o uploade de nenhum arquivo sequer.
Isso ocorre em todas as implementações em domínios de diferentes clientes.
Ao tentar fazer o upload de um arquivo ou imagem, obtenho o seguinte erro:
Microsoft VBScript runtime error '800a01a8'
Object required: '[undefined]'
/upload.asp, line 278
Ao verificar esta linha do arquivo encontrei o seguinte código que sempre funciona há mais de 5 anos e parou do nada:
contentType = UploadRequest.Item("blob").Item("ContentType")
Fui rastreando este erro e descobri que ele está relacionado a esta sub, BuildUploadRequest, que é quem trata os dados binários do arquivo e seta o objeto UploadRequest. Aparentemente ela parou de funcionar e não atribui nada no objeto por algum motivo que não consigo descobrir.
Já verifiquei permissões de leitura, e até imprimi o total de bytes que está chegando por post.
Em resumo, o arquivo está indo mas o asp não consegue tratar o binário para fazer o upload.
Alguém pode me ajudar?
Abaixo segue o código de um arquivo de upload que não funciona mais e antes funcionava perfeitamente:
<%
Sub BuildUploadRequest(RequestBin)
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
If PosFile<>0 AND (PosFile<PosBound) Then
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Sub
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
%>
<html>
<head>
<script language="JavaScript1.2">
function abre_janela(width, height, nome) {
var top; var left;top = ( (screen.height/2) - (height/2) )
left = ( (screen.width/2) - (width/2) )
window.open('',nome,'width='+width+',height='+height+',scrollbars=yes,toolbar=no,location=no,status=no,menubar=yes,resizable=no,left='+left+',top='+top);
}
function confirm_delete(form) {if (confirm("Tem certeza que deseja excluir esta imagem?")) {
document[form].submit();}}
function high(which2){
theobject=which2
highlighting=setInterval("highlightit(theobject)",50)
}
function low(which2){
clearInterval(highlighting)
which2.filters.alpha.opacity=20
}
function highlightit(cur2){
if (cur2.filters.alpha.opacity<100)cur2.filters.alpha.opacity+=5
else if (window.highlighting)
clearInterval(highlighting)
}
PositionX = 100;
PositionY = 100;
defaultWidth = 500;
defaultHeight = 500;
var AutoClose = true;
// Do not edit below this line...
// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
writeln('width=100-(document.body.clientWidth-document.imagens[0].width);');
writeln('height=100-(document.body.clientHeight-document.imagens[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');
writeln('window.innerWidth=document.imagens["George"].width;');writeln('window.innerHeight=document.imagens["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
close();
}}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css"><!--
body,td,th {
font-family: Arial;
font-size: 12px;
color: #333;
}-->
</style>
</head>
<body style="background-color:#f8f8f8"><%
'----------------------------------------------------------------------------
' MATA OS ACENTOS
'----------------------------------------------------------------------------
Function KillAcentos(Palavra)
cacento = "àáâãäèéêëìíîïòóôõöùúûüÀÁÂÃÄÈÉÊËÌÍÎÒÓÔÕÖÙÚÛÜçÇñÑ^~ºª´`'&%"
sacento = "aaaaaeeeeiiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN"
texto = ""
'Response.Write "----"&Len(Palavra)&"---"
'Response.Write Palavra
If Palavra <> "" Then
For controlador = 1 To Len(Palavra)
letra = Mid(Palavra, controlador, 1)
pos_acento = InStr(cacento, letra)
If pos_acento > 0 Then
letra = Mid(sacento, pos_acento, 1)
End If
texto = texto & letra
Next
KillAcentos = lcase(Replace(texto,Chr(32), Chr(45)))
End If
End Function
'----------------------------------------------------------------------------
' MATA OS ACENTOS
'----------------------------------------------------------------------------
Function KillAcentos2(Palavra)
cacento = "àáâãäèéêëìíîïòóôõöùúûüÀÁÂÃÄÈÉÊËÌÍÎÒÓÔÕÖÙÚÛÜçÇñÑ^~ºª´`'&%"
sacento = "aaaaaeeeeiiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN"
texto = ""
'Response.Write "----"&Len(Palavra)&"---"
'Response.Write Palavra
If Palavra <> "" Then
For controlador = 1 To Len(Palavra)
letra = Mid(Palavra, controlador, 1)
pos_acento = InStr(cacento, letra)
If pos_acento > 0 Then
letra = Mid(sacento, pos_acento, 1)
End If
texto = texto & letra
Next
KillAcentos2 = texto
End If
End Function
id = "1"
pasta_servidor = "teste"
website_pasta = "E:\Inetpub\vhosts\multiplicacaodigital.com.br\httpdocs\"
website_url = "http://www.multiplicacaodigital.com.br"
StrFolder = website_pasta& "imagens\" &pasta_servidor& "\" &id& "\"
'Response.Write StrFolder
fotos_limite = 8
'# CRIA A PASTA, CASO AINDA NAO EXISTA
Set objFS = Nothing
Set objFolder = Nothing
Set objFS = Server.CreateObject("Scripting.FileSystemObject")
'Response.Write StrFolder
If Not objFS.FolderExists(StrFolder) Then
objFS.CreateFolder(StrFolder)
End if
Set objFolder = ObjFS.GetFolder(StrFolder)
For Each File in objFolder.files
If lcase(Right(File, 3)) = "gif" Or lcase(Right(File, 3)) = "jpg" Or lcase(Right(File, 3)) = "png" Then
'Response.Write File.Name
If Not(objFS.FileExists(StrFolder&KillAcentos(File.Name))) Then
File.Name = KillAcentos(File.Name)
End If
End If
Next
Set objFS = Nothing
Set objFolder = Nothing
x = 0
Set objFS = Server.CreateObject("Scripting.FileSystemObject")
If Not objFS.FolderExists(StrFolder) Then
objFS.CreateFolder(StrFolder)
End if
Set objFolder = ObjFS.GetFolder(StrFolder)
For Each File in objFolder.files
If lcase(Right(File, 3)) = "gif" Or lcase(Right(File, 3)) = "jpg" Or lcase(Right(File, 3)) = "png" Then
x = x + 1
End If
Next
%>
<table width="0%" border="0" cellspacing="8" cellpadding="0" class="texto1" style="border-bottom: 1px solid white">
<tr>
<td colspan="<%=x%>">
<% If x = 0 Then %>
Nao existem fotos cadastradas.
<% End If %>
</td>
</tr>
<tr>
<%
If Request("remover") <> "" Then
Set objFS = Server.CreateObject("Scripting.FileSystemObject")
If objFS.FileExists( StrFolder & Request("imagem_remover") ) Then
objFS.DeleteFile( StrFolder & Request("imagem_remover") )
Set objFS = Nothing
End If
End If
x = 0
'# EXIBE AS FOTOS QUE FORAM ENVIADAS
For Each File in objFolder.files
If lcase(Right(File, 3)) = "gif" Or lcase(Right(File, 3)) = "jpg" Or lcase(Right(File, 3)) = "png" Then
x = x + 1
%>
<form name="form_<%=x%>" method="post" action="<%=Request.ServerVariables("SCRIPT_NAME")%>?pasta_servidor=<%=pasta_servidor%>&id=<%=id%>&remover=sim&website_pasta=<%=website_pasta%>">
<input type="hidden" name="imagem_remover" value="<%=File.Name%>">
<td valign="top" align="center"><a href="<%=website_url%>/imagens/<%=Request("pasta_servidor")%>/<%=Request("id")%>/<%=File.Name%>" onClick="abre_janela(777, 550, 'popup','yes')" target="popup"><img src="<%=website_url%>/imagens/<%=pasta_servidor%>/<%=id%>/<%=File.Name%>" border="0" width="50" height="50" style="border: 1px solid black"></a><br>
<input type="button" onClick="confirm_delete('form_<%=x%>')" value="Apagar">
</td>
</form>
<%
End If
Next
%>
</tr>
</table><%
Set objFolder = Nothing
Set Folder = Nothing
%>
<%
If Request("enviar") <> "" And Request("ignorar") = "" Then
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
contentType = UploadRequest.Item("blob").Item("ContentType")
filepathname = UploadRequest.Item("blob").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Items("blob").Item("Value")
If Lcase(Right(filename,3)) = "jpg" Or Lcase(Right(filename,3)) = "gif" Or Lcase(Right(filename,3)) = "png" then
Set objFS = Server.CreateObject("Scripting.FileSystemObject")
If objFS.FileExists(strFolder & filename) Then
%>
<script language="javascript">
alert("Erro ao enviar imagem, o arquivo '<%=filename%>' já existe na pasta de imagens do produto")
</script>
<%
Else
If LenB(value) > 400000 then
%>
<script language="javascript">
alert("Erro ao enviar a imagem, o tamanho do arquivo deve ser menor que 400Kb")
</script>
<%
Else
%>
<br><strong>Aguarde o envio da imagem...</strong><br>
<input name="progress" id="progress" value="0% enviado" style="border:none;background-color:#FFFFFF">
<table width="100" border="0" cellspacing="0" cellpadding="0" style="border: 1px inset;background-color:#FFFFFF">
<tr>
<td><input name="barra" id="barra" style="border:none; background-color: orangered; height: 10; width:1" readonly></td>
<td></td>
</tr>
</table>
<%
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
filename = Replace(filename," ","")
'Response.Write "--"&filename2&"--"
Set MyFile = ScriptObject.CreateTextFile( StrFolder & filename)
progress = 0
n = 3
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
progress = Fix((i * 100) / LenB(value))
If n <> progress then
n = progress
%>
<script language="javascript">document.getElementById('progress').value = "<%=n%>% enviado"</script>
<script language="javascript">document.getElementById('barra').style.width = "<%=n%>"</script>
<%
End if
Next
MyFile.Close
If n=progress Then
%>
<form name="reload" id="reload" method="post" action="">
</form>
<script language=javascript>
document.getElementById('reload').action =window.location + "&ignorar=sim";
document.getElementById('reload').submit();
</script>
<%
End If
End If
Set objFS = Nothing
End ifElse
%>
<script language="javascript">
alert("Erro ao enviar a imagem, lembre-se que ela deve possuir extensao PNG, JPG ou GIF");
</script>
<%
End IfEnd If
%>
<%
Set ObjFS = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = ObjFS.GetFolder(StrFolder)
x = 0
For Each File in objFolder.files
If lcase(Right(File, 3)) = "gif" Or lcase(Right(File, 3)) = "jpg" Or lcase(Right(File, 3)) = "png" Then
x = x + 1
End If
Next
Set ObjFS = Nothing
Set objFolder = Nothing
%>
<table width="100%" border="0" cellspacing="20" cellpadding="0" style="background-color:#F3F3F3" class="texto1">
<tr>
<form method="post" enctype="multipart/form-data" action="<%=Request.ServerVariables("SCRIPT_NAME")%>?pasta_servidor=<%=pasta_servidor%>&id=<%=id%>&enviar=sim&website_pasta=<%=website_pasta%>">
<td class="texto_pagina" valign="top">
<%If x => 8 Then%>
<strong>Permitido enviar o total de 8 fotos.</strong><br>
<%Else%>
<strong>Envio de nova foto:</strong><br>
<input type="file" name="blob" class="texto_pagina" style="width:200px" src="img/pesquisar_imagem.gif"><br><br>
<input type="submit" value="Enviar">
<%End If%>
</td>
</form>
</tr>
</table>
</body>
</html>Discussão (0)
Carregando comentários...