Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Coloboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 17-08-2008
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Poder: 26
seoane Va por buen camino
Cita:
Empezado por roman Ver Mensaje
Hey, pensé que ibas a poner la solución usando wininet
Si es que entro al trapo enseguida

Aquí tienes el código roman, pero aviso que esta bastante sucio y tiene algo de copy&paste de otros proyectos, pero aquí es la una de la madrugada (mas bien una y media) y no voy a dedicarle mas tiempo

Código Delphi [-]
uses
  WinInet;

const
  strSeparador = 'Separador528C65E88C1F4DB5BDB11BF1558AF1C3';

function UploadImage(Filename: String): String;
var
  hNet: HINTERNET;
  hCon: HINTERNET;
  hReq: HINTERNET;
  Context: DWORD;
  BytesRead: DWORD;
  Data: TMemoryStream;
  Response: TStringStream;
  Buffer: PChar;
  Str: String;
  FileStream: TFileStream;
  i: Integer;
begin
  Result:= EmptyStr;
  Context:= 0;
  hNet := InternetOpen('Agente', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if (hNet <> nil) then
  begin
    hCon:= InternetConnect(hNet,'img.tomatone.net',80,nil,nil,
      INTERNET_SERVICE_HTTP,0,Context);
    if (hCon <> nil) then
    begin
      hReq:= HttpOpenRequest(hCon,'POST','/index.php',nil,nil,nil,
          INTERNET_FLAG_RELOAD,Context);
      if (hReq <> nil) then
      begin
        Data:= TMemoryStream.Create;
        try
          // Agregamos el campo
          Str:= '--' + strSeparador + #13#10;
          Data.WriteBuffer(PChar(Str)^,Length(Str));
          Str:= 'Content-Disposition: form-data; name="comp"'
          + #13#10#13#10 + 'ok' + #13#10;
          Data.WriteBuffer(PChar(Str)^,Length(Str));
          // Agregamos el archivo
          Str:= '--' + strSeparador + #13#10;
          Data.WriteBuffer(PChar(Str)^,Length(Str));
          Str:= 'Content-Disposition: file; name="userfile"; filename="' + ExtractFilename(Filename) + '"' + #13#10;
          Data.WriteBuffer(PChar(Str)^,Length(Str));
          Str:= 'Content-Type: image/jpeg' + #13#10;
          Data.WriteBuffer(PChar(Str)^,Length(Str));
          Str:= 'Content-Transfer-Encoding: binary' + #13#10#13#10;
          Data.WriteBuffer(PChar(Str)^,Length(Str));
          FileStream:= TFileStream.Create(Filename,fmOpenRead);
          try
            Data.CopyFrom(FileStream,0)
          finally
            FileStream.Free;
          end;
          Str:= #13#10 + '--' + strSeparador + '--' + #13#10;
          Data.WriteBuffer(PChar(Str)^,Length(Str));
          if HttpSendRequest(hReq,
            PChar('Content-Type: multipart/form-data; boundary='
            + strSeparador), Cardinal(-1), Data.Memory,Data.Size) then
          begin
            Response:= TStringStream.Create(EmptyStr);
            try
              GetMem(Buffer,32*1024);
              try
                while (InternetReadFile(hReq,Buffer,32*1024,BytesRead)) do
                begin
                  if (BytesRead = 0) then
                    break;
                  Response.Write(Buffer^,BytesRead)
                end; 
                Str:= Response.DataString;
                // Esto se lo copio a roman
                I := Pos('href=''big/', Str);
                if I > 0 then
                begin
                  Delete(Str, 1, I + 9);
                  I := Pos('''', Str);
                  if I > 0 then
                  begin
                    Result := 'http://img.tomatone.net/big/' + Copy(Str, 1, I - 1);
                  end;
                end;
                // Fin del plagio
              finally
                FreeMem(Buffer);
              end;
            finally
              Response.Free;
            end;
          end;
        finally
          Data.Free;
        end;
        InternetCloseHandle(hReq);
      end;
      InternetCloseHandle(hCon);
    end;
    InternetCloseHandle(hNet);
  end;
end;

Última edición por seoane fecha: 17-08-2008 a las 00:40:57.
Responder Con Cita
  #2  
Antiguo 19-08-2008
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Poder: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
gulder, retomando esto, ojalá te sirva la solución de seoane. Debo comentar que la mia la probé y funciona bien con Indy 10, pero al probarla en casa con Indy 9 no funciona y el sitio en cuestión no manda ningún mensaje aclaratorio. Tengo la impresión de que no está mandando correctamente el archivo, pero no he tenido oportunidad de profundizar.

¿Cuál versión estás usando tú?

// Saludos
Responder Con Cita
  #3  
Antiguo 20-08-2008
Avatar de gulder
gulder gulder is offline
Miembro
 
Registrado: abr 2005
Ubicación: colombia-sucre
Posts: 384
Poder: 22
gulder Va por buen camino
Thumbs up

hola a todos como andan disculpen enormemente por abandonar este pots siendo yo el que mas le interesaba pero fue por causa de fuerza mayor, siguiendo por donde iba Román no me funciona por que yo uso las indy 9 entonces por eso no me funcionaba lo que tu expones.
Y seocene en estos momentos estoy probando lo que me dices saludos y gracias a los dos por no desmotivarse
Responder Con Cita
  #4  
Antiguo 20-08-2008
Avatar de gulder
gulder gulder is offline
Miembro
 
Registrado: abr 2005
Ubicación: colombia-sucre
Posts: 384
Poder: 22
gulder Va por buen camino
Thumbs up

hola foro seoane funciona a la perfeccion gracias
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
No se ven imagenes en Internet Explorer Albano Internet 10 09-01-2006 20:43:51
Primeras imágenes de Internet Explorer 7 marcoszorrilla Noticias 1 02-08-2005 03:54:16
Descargar imágenes de internet via http. alfredosg19 Internet 2 08-04-2005 13:02:27


La franja horaria es GMT +2. Ahora son las 01:39:14.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi