Saturday, January 29, 2011

ASP uploading/transferring images

I have an ASP web service, that allows to various users to put some data in a database and to upload some images. Since the users have different web sites, the web service uploads the image in a first directory in its own space, then calls an ASP web page located in the user's domain passing it the path to the image (correctly stored) as follows:

MResponseBackAsp(Session("Dominio") & "trasferisci.asp?nomefile=" & Session.SessionID & "-" & name)

So, here it comes the trouble, I receive the following message:

Microsoft VBScript runtime error '800a0005' 
Invalid procedure call or argument 
/trasferisci.asp, line 28 Si รจ verificato un errore nel salvataggio dell'immagine

The code relative to that line is commented:

<%  
nomeFile = Request("nomefile")

Dim lStato
Dim objHTTP
Dim strDataIn
'Randomize()

Set objHTTP = CreateObject("Microsoft.XMLHTTP") 
objHTTP.Open "GET", "http://URL/" & nomeFile, False 
objHTTP.Send 
lStato= objHTTP.Status
strDataIn= objHTTP.ResponseBody 'Binario 
Set objHTTP = Nothing 

If (lStato<>200) Or (Err.Number<>0) Then 
  problema = "Errore " & lStato & " o " & Err.Description & "."
End If

newNomeFile = right(nomeFile,len(nomeFile)-instr(nomeFile,"-"))
fileDaSalvare = Server.mapPath(Application("news_immagini") & newNomeFile)

Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(fileDaSalvare) Then objFSO.DeleteFile(fileDaSalvare)
Set objFl = objFSO.CreateTextFile(fileDaSalvare, true)
objFl.Write BinaryToString(strDataIn)
objFl.Close()
Set objFl = Nothing
Set objFSO = Nothing

Function BinaryToString(Binary) 
  dim c1, c2, c3, p1, p2, p3 
  Dim L 
  c1 = 1 :  c2 = 1 : c3 = 1 
  L = LenB(Binary) 

  Do While c1<=L 
    p3 = p3 & Chr(AscB(MidB(Binary,c1,1))) 
    c1 = c1 + 1 : c3 = c3 + 1 
    if c3>300 then 
      p2 = p2 & p3 
      p3 = "" 
      c3 = 1 
      c2 = c2 + 1 
      if c2>200 then 
        p1 = p1 & p2 
        p2 = "" 
        c2 = 1 
      End If 
    End If 
  Loop 
  BinaryToString = p1 & p2 & p3 
End Function

Response.write "salvato"
%>

But the best parts come now: 1) If we call trasferisci.asp manually it works; 2) If we refresh the global.asa then it works again for a while

I read somewhere that there could be some problems whit image upload, where is the problem? Suggestions?

Thank you all folks.

PS (edit): I've posted this question here because we think that the problems are into the System, not into the code. I apologyze if it is not.

  • The error message

    Microsoft VBScript runtime error '800a0005'
    Invalid procedure call or argument

    while uploading files is probably related to the server. It may not support some of the newer functions of VBScript.

    Maybe it has an older or outdated version of the Microsoft Data Access Components (MDAC) and/or VBScript.


    By the way, shouldn't you use the

     Response.BinaryWrite()
    

    method when writing binary data?

    Also, I would issue Response.Clear() and set the right HTTP response header (according to the files MIME type): Response.ContentType = "...".

    IssamTP : Thank you for your answer, we've analyzed your suggestions, but unfortunately we couldn't find the solutions. Anyway, just to be sure, we've posted the whole code of the original file "trasferisci.asp", hoping that this will help to fix.
    IssamTP : The DLL version is 8.100.1051.0
    splattne : okay, I see. I just don't understand why you're creating text files if you could save them as binary files. Is there a special reason? I guess the problem could be some strange strings being created from your binary content (image). Also, it could be a problem if browsers/sites use different text encodings (Windows-1252, UTF8, ...)
    IssamTP : Yes, technically it would be better using ADODB.Stream, but the main web programmer says that it causes troubles with anti-virus.
    From splattne

0 comments:

Post a Comment