synopse / mORMot2

OpenSource RESTful ORM/SOA/MVC Framework for Delphi and FreePascal
https://synopse.info
Other
485 stars 122 forks source link

added callback for upload #198

Closed danielkuettner closed 1 year ago

danielkuettner commented 1 year ago

example for uploading file:

function FTPUploadFile(const pmcUrl, pmcUserName, pmcPassword: RawUtf8; const pmvContent: RawByteString): TCurlResult; var hnd: TCurl; Upload: TTransfer; begin Result := crFailedInit; if not CurlIsAvailable then Exit; //=>

hnd := curl.easy_init; if hnd <> Nil then begin Upload.buf:= PAnsiChar(pmvContent); Upload.size:= Length(pmvContent); Upload.uploaded:= 0;

curl.easy_setopt(hnd, coReadFunction, @CurlReadRawByteString);
curl.easy_setopt(hnd, coUpload, 1);
curl.easy_setopt(hnd, coURL, Pointer(pmcUrl));
curl.easy_setopt(hnd, coUserName, Pointer(pmcUserName));
curl.easy_setopt(hnd, coPassword, Pointer(pmcPassword));
curl.easy_setopt(hnd, coReadData, @Upload);
curl.easy_setopt(hnd, coInFileSize, Length(pmvContent));
Result := curl.easy_perform(hnd);
curl.easy_cleanup(hnd);

end; end;

... url:= cUrl + filename; buffer:= StringFromFile('SOneSrv2.log'); if FTPUploadFile(url, u, p, buffer) = crOk then doSomething;

danielkuettner commented 1 year ago

There are 1 mistake in my PR:

coReadData = coInFile (instead of coFile)

and in row 904 StrLCopy should be replaced with

MoveFast((Upload.buf + Upload.uploaded)^, buffer^, Result);

Thanks and sorry for the mistake, Daniel

synopse commented 1 year ago

Could you please update your PR ?

danielkuettner commented 1 year ago

200