PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 24 → Salvar Imagem em DB
Salvar Imagem em DB
Débuté par adrianoboller, 24 nov. 2014 12:44 - 1 réponse
Membre enregistré
2 958 messages
Popularité : +89 (91 votes)
Posté le 24 novembre 2014 - 12:44
Procedure CAM_SalvarDB(LOCAL ArquivoLocal,...
LOCAL Extensao,...
LOCAL Ambiente,...
LOCAL Crypto,...
LOCAL OpcaoEscolha,...
LOCAL CodigoArquivo,...
LOCAL CodOs,...
LOCAL CodOsItem,...
LOCAL NomeArquivo,...
LOCAL Descricao,...
LOCAL VideoFoto,...
LOCAL TempoSegundos,...
LOCAL FPS,...
LOCAL DebugSN)

//info("CAM_SalvarDB")
IF gsDebugSN = "S"
DebugSN="S"
END

UltimoCodigo is int = 0

IF VideoFoto = "Foto"
gloWidth = Middle(gsResolucao,1,3)
IF gloWidth = "" OR gloWidth = 0 THEN
gloWidth = 640
END
gloHeight = Middle(gsResolucao,5,3)
IF gloHeight = "" OR gloHeight = 0 THEN
gloHeight = 480
END
END


IF DebugSN = "S" THEN
NextTitle("Os")
Info(gloWidth,gloHeight)
END


//T001 - Campos de Armazenamento dos arquivos

IF VideoFoto = "Foto"
T020Arquivo.Tipo020 = "Foto"
ELSE IF VideoFoto = "Video"
T020Arquivo.Tipo020 = "Video"
END

T020Arquivo.CodOrdemServico018 = GloCodOS

T020Arquivo.CodOrdemServicoStatus018 = GloCodItemOS

T020Arquivo.PathUrl020 = ArquivoNovo

T020Arquivo.Observacao020 = Descricao

T020Arquivo.DataHora020 = DateToString(DateSys()) +" - "+ TimeToString(TimeSys())


IF VideoFoto = "Foto"
T020Arquivo.FotoVideo020 = dLoadImage(ArquivoNovo,imgDefault,gloWidth,gloHeight)
ELSE IF VideoFoto = "Video"
T020Arquivo.FotoVideo020 = dLoadImage(ArquivoNovo)
END

ok = HAdd(T020Arquivo)

IF ok = True THEN

IF DebugSN = "S" THEN
NextTitle("Os")
Info("Gravado na base de dados com sucesso!")
END

ok = HExecuteQuery(QRY_MAX_T020)
HReadFirst(QRY_MAX_T020,QRY_MAX_T020.Count_1,hKeepFilter)
UltimoCodigo = QRY_MAX_T020.Count_1

//Enviar para Webservice//
IF DebugSN = "S" THEN
NextTitle("Os")
Info(Crypto,UltimoCodigo,CodOsItem,Descricao,DebugSN)
Info(CodOs, CodOsItem, ArquivoLocal, Extensao, NomeArquivo)
END

IF CodigoArquivo = 0 OR CodigoArquivo = "" THEN
CodigoArquivo = UltimoCodigo
END


//---------------------------------------------//
CAM_Enviar2WS( ArquivoLocal,...
Extensao,...
Ambiente,...
Crypto,...
OpcaoEscolha,...
CodigoArquivo,...
CodOs,...
CodOsItem,...
NomeArquivo,...
Descricao,...
VideoFoto,...
TempoSegundos,...
FPS,...
DebugSN )
//---------------------------------------------//


ELSE
//Importante exibir o erro
NextTitle("Os")
Info("Erro ao gravar na base de dados",ErrorInfo())

END
Membre enregistré
2 958 messages
Popularité : +89 (91 votes)
Posté le 05 avril 2016 - 22:12
Prezados,

Segue alguns detalhes apontados pelo Danilo Valim

//********************************************************************
//Gerando imagem usando crypt
//********************************************************************
bufImageBuffer is Buffer = ""
sImageString is string = ""

bufImageBuffer = fLoadBuffer(IMG_1)

sImageString = Crypt(bufImageBuffer,"",cryptNone)
//sImageString = Crypt(bufImageBuffer,"TesteSenhaCript",cryptFast) //Com criptografado com senha

//info(length(sImageString)) - Qtde de Caracteres da Imagem Serializada - 3324508




//********************************************************************
//Usando Código dessa Forma Consigo Inserir uma Imagem de Tamanho - 2,31 Mb
//********************************************************************
gdsConsulta is Data Source
HClose(gdsConsulta)

gsQuery is string = "Execute Cadastro_Anexo "+EDT_Nome_Imagem+" ,'"+sImageString+"',0"
IF NOT HExecuteSQLQuery(gdsConsulta,CONN2, hQueryWithoutCorrection, gsQuery) THEN
Info(HErrorInfo())
ELSE
HReadFirst(gdsConsulta, MsgProd)
WHILE HOut() = False
IF gdsConsulta.MsgProd <> "OK" THEN
Error(gdsConsulta.MsgProd)
ELSE
Info("OK")
END
HReadNext(gdsConsulta)
END
END



//*********************************************************************************
//Usando esse Código, dessa Forma da Estouro de Buffer, Variavel sImageString
//vai Cortada e da Erro, não funciona, não use HEXECUTEQUERY, USE
//HEXECUTESQLQUERY, É MAIS ADEQUADO.
//***********************************************************************************
IF HExecuteQuery(QRY_Insert_Foto,hQueryDefault,EDT_Nome_Imagem,sImageString) = False THEN
Info(HErrorInfo())
ELSE
Info("Imagem salva com Sucesso!!")
END



//*********************************************************************************
//Dessa Forma também da Estouro de Buffer, Variavel sImageString vai
//Cortada e da Erro, não funciona
//***********************************************************************************
dsQry_Sql is Data Source

sQl_execute is string =
[
Insert INTO Anexo_Teste
(
NomeAnexo,
Foto
)
VALUES
(
'@NomeAnexo@',
'@Foto@'
)
]

sQl_execute = Replace(sQl_execute,"@NomeAnexo@",EDT_Nome_Imagem)
sQl_execute = Replace(sQl_execute,"@Foto@",sImageString)

ok is boolean = HExecuteSQLQuery(dsQry_Sql,hQueryDefault+hCheckDuplicates+hCheckIntegrity,sQl_execute)
IF ok = True THEN
Info("OK")
ELSE
Info(HErrorInfo(),ErrorInfo())
END




//***********************************
Conteudo da variavel sImageString
//***********************************

/9j/4QJMRXhpZgAASUkqAAgAAAAMAAABBAABAAAAIBAAAAEBBAABAAAAGAwAAA8BAgAIAAAAngAAABAB
AgAJAAAApgAAABIBAwABAAAABgAAABoBBQABAAAAsAAAABsBBQABAAAAuAAAACgBAwABAAAAAgAAADEB
AgANAAAAwAAAADIBAgAUAAAAzgAAABMCAwABAAAAAQAAAGmHBAABAAAA4gAAAAAAAABTQU1TVU5HAEdU
LUk5NTA1AABIAAAAAQAAAEgAAAABAAAASTk1MDVWSlVFTUtFAAAyMDE0OjA0OjAzIDIzOjI0OjA4AA8A
IogDAAEAAAACAAAAAJAHAAQAAAAwMjIwA5ACABQAAACcAQAABJACABQAAACwAQAAAZEHAAQAAAABAgMA
B5IDAAEAAAACAAAAfJIHAGIAAADEAQAAAKAHAAQAAAAwMTAwAaADAAEAAAABAAAAAqAEAAEAAAAgEAAA
A6AEAAEAAAAYDAAABaAEAAEAAAAmAgAAAqQDAAEAAAAAAAAAA6QDAAEAAAAAAAAABqQDAAEAAAADAAAA
AAAAADIwMTQ6MDQ6MDMgMjM6MjQ6MDgAMjAxNDowNDowMyAyMzoyNDowOAAHAAEABwAEAAAAMDEwMAIA
BAABAAAAACABAAwABAABAAAAAAAAABAABQABAAAAWgAAAEAABAABAAAAAAAAAFAABAABAAAAAQAAAAAB
AwABAAAAAAAAAAAAAAAAAAAAAAAAAAIAAQACAAQAAABSOTgAAgAHAAQAAAAwMTAwAAAAAP/bAIQAAQEB
AQEBAQEBAQEBAQICAwICAgICBAMDAgMFBAUFBQQEBAUGBwYFBQcGBAQGCQYHCAgICAgFBgkKCQgKBwgI
CAEBAQECAgIEAgIECAUEBQgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI
CAgICAgI/8AAEQgMGBAgAwEiAAIRAQMRAf/EAaIAAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKCxAA
AgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRol
JicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZ
mqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6AQAD ........


//Obs: Nao da certo de terminar de montar o INSERT, Corta no meio o Insert.


:merci:

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.blogspot.com.br/