Skip to content

MULTIPART/FORM-DATA exception #154

@kidultttttt

Description

@kidultttttt

Hello! I'm trying to post an image.
Unfortunately, the process doesn't work.
The current routine is as follows.
The problem is, the following exception is thrown: E2010 Incompatible types: 'string' and 'TObject'
Shouldn't the post method receive such a parameter?

...
   TRequestFoto = class(TMultiPartFormData)
      vCaminhoFoto : TMultiPartFormAttachment;
   end;
...
function TuMercadoLivre.ValidaFoto(vCaminho, vToken : String): TJSONObject;
var
   vResponse : String;
   vRestClient : TRestClient;
   vRequestFoto : TRequestFoto;
begin
   vRequestFoto := TRequestFoto.Create;
   vRestClient := TRestClient.Create(Nil);
   Try
      Try
         vRestClient.ConnectionType := hctWinHttp;

         vRequestFoto.vCaminhoFoto := TMultiPartFormAttachment.Create('C:\SysFire\MercadoLivreFoto\000000000060_1.jpeg', 'multipart/form-data', '000000000060_1.jpeg');

         vResponse := vRestClient.
                      Resource('https://api.mercadolibre.com/pictures/items/upload').
                      Header('Authorization', 'Bearer ' + vToken).
                      ContentType('multipart/form-data').
                      Post(vRequestFoto);

         Result := TJSONObject(TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(vResponse), 0));
      Except
         On E : Exception Do
            Raise Exception.Create(E.Message);
      End;
   Finally
      vRestClient.Free;
      vRequestFoto.Free;
   End;
end;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions