
Subir cualquier archivo al WebService [ASP.NET/Cordova]
Publicado por Joel (2 intervenciones) el 02/02/2016 10:06:55
Hola llevo ya unos días atascado en poder subir un archivo(de cualquier tipo) desde Cordova mediante SOAP a un Servicio ASP.NET para que lo guarde en el servidor, pero la información que he encontrado no me ha funcionado, a ver si alguien puede ayudarme soy de Ciclo Superior me han puesto a cargo de este proyecto en unas practicas y estoy perdidisimo ya que acabo de aprender como funciona ASP.Net hace poco.
El Servicio es este al cual le paso el archivo en Base64String, pero me da error 500 en el JSON no se si es que he declarado mal los parametros, TIP: el archivo tmb lo intente pasar en array de bytes y no me funciono
Cualquier ayuda gracias de antemano.

El Servicio es este al cual le paso el archivo en Base64String, pero me da error 500 en el JSON no se si es que he declarado mal los parametros, TIP: el archivo tmb lo intente pasar en array de bytes y no me funciono
Cualquier ayuda gracias de antemano.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<WebMethod()>
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)>
Public Function uploadFile(ByVal user As String, ByVal pass As String, ByVal server As String, ByVal database As String, ByVal tabla As String, ByVal sIDRegistro As String, ByVal categoria As String, ByVal descripcion As String, ByVal file As String, ByVal fileName As String) As String
Dim bytes As Byte() = Convert.FromBase64String(file)
Dim objJSSerializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim conn As New SqlClient.SqlConnection
Dim selectSQL As String = ""
Dim statusJSON As String = ""
Dim resJSON As String = ""
Dim rutaIns As String = ""
Dim sSQL As String = ""
Dim resultJSON As New Dictionary(Of String, Object)
If Not connectToSql(conn, user, pass, server, database) Then
statusJSON = "KO"
resJSON = "Error de conexión con la Base de Datos"
Else
Dim sSQL2 As String = ""
sSQL2 = "SELECT * FROM TDocumAdjuntos WHERE Tabla='" & tabla & "'"
sSQL2 = sSQL2 & " AND IDRegistro=" & sIDRegistro
sSQL2 = sSQL2 & " AND Categoria='" & categoria & "'"
sSQL2 = sSQL2 & " AND NombreArchivo='" & descripcion & "'"
Dim aux As Object
aux = RS_DT(sSQL2, conn)
If aux.Rows.Count > 0 Then
Return False
End If
selectSQL = "select top 1 Valor from MProductoParametro where Parametro = 'PATH_INCRUSTADOS' and Producto in " &
"(select Producto from MProducto where Instalado = '1')"
rutaIns = DameValor(selectSQL, conn)
Dim ruta As String = rutaIns + "\" + database
If rutaIns <> "" Then
If Not (My.Computer.FileSystem.DirectoryExists(ruta & "\" & tabla)) Then
MkDir(ruta & "\" & tabla)
End If
If Not (My.Computer.FileSystem.DirectoryExists(ruta & "\" & tabla & "\" & sIDRegistro)) Then
MkDir(ruta & "\" & tabla & "\" & sIDRegistro)
End If
If Not (My.Computer.FileSystem.DirectoryExists(ruta & "\" & tabla & "\" & sIDRegistro & "\" & categoria)) Then
MkDir(ruta & "\" & tabla & "\" & sIDRegistro & "\" & categoria)
End If
End If
Try
Dim ms As New MemoryStream(bytes)
Dim fs As New FileStream(ruta & "\" & tabla & "\" & sIDRegistro & "\" & categoria & "\" & fileName, FileMode.Create)
Dim dirpath As String = ruta & "\" & tabla & "\" & sIDRegistro & "\" & categoria
' ' instance a memory stream and pass the
' ' byte array to its constructor
' Dim ms As New MemoryStream(decodedBytes)
' ' instance a filestream pointing to the
' ' storage folder, use the original file name
' ' to name the resulting file
' Dim fs As FileStream = New FileStream(ruta & "\" & tabla & "\" & sIDRegistro & "\" & categoria & "\" & fileName, FileMode.Create)
' ' write the memory stream containing the original
' ' file as a byte array to the filestream
ms.WriteTo(fs)
' ' clean up
ms.Close()
fs.Close()
fs.Dispose()
' ' return OK if we made it this far
sSQL = "INSERT INTO TDocumAdjuntos (Tabla,IDRegistro,Categoria,PathVinculacion,NombreArchivo,Descripcion,PalabrasClave,ESOLE,OLKM001) VALUES ('" & tabla & "', '" & sIDRegistro & "' ,'" & categoria & "','" & dirpath & "','" & fileName & "','" & descripcion & "','Archivo',0,NULL ) "
'' 'archivosTreeView.Rows.Add(txtArchivo.Text, rutaFichero, sSQL)
executeQuery(sSQL, conn)
Catch ex As Exception
' ' return the error message if the operation fails
statusJSON = "KO Fallo en el insert"
End Try
statusJSON = "OK"
'Pasamos la lista a JSON
resJSON = "Correcto"
End If
resultJSON.Add("status", statusJSON)
resultJSON.Add("result", resJSON)
Return objJSSerializer.Serialize(resultJSON)
End Function
Valora esta pregunta


0