我正在使用 Delphi XE5 在服务器上上传文件。我使用 php 脚本将文件上传到服务器上的目录中,它工作正常。代码是
德尔福代码
Function Upload(sfilepath : string) : string;
var
Params: TIdMultipartFormDataStream;
Response: TStringStream;
http: TIdHttp;
begin
try
http := TIDHttp.Create(nil);
http.HandleRedirects := true;
http.ReadTimeout := 5000;
http.Request.ContentType:='multipart/form-data';
Params := TIdMultipartFormDataStream.Create;
Response := TStringStream.Create;
try
Params.AddFile('file',sfilepath , 'image/jpg'); // 'C:\Sc.png'
http.Post('http://xxx.xxx.x.xx:8080/mages/php/uploadFilesToserverDirectory.php', Params, Response);
result:=Response.DataString;
finally
Params.Free;
Response.Free;
http.Free;
end;
except
on e: Exception do
ShowMessage(e.Message);
end;
end;
php代码
< ?php
if (isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK)
{
$target = 'uploads/'. time();
$result = move_uploaded_file($_FILES['file']['tmp_name'], $target);
if (!$result) {
echo 'Cannot copy'; }
}
这在 Windows 上运行良好,因为我可以使用 Topendialog 并发送路径 Params.AddFile('file',sfilepath , 'image/jpg');
但是如何在 iOS 中做到这一点?我想浏览图像(或任何文件)并获取其路径以将其作为参数发送到 Function Upload(sfilepath : string) : string; ?
来自的样本\RAD Studio\12.0\Samples\MobileCodeSnippets\CameraRoll
没有给我图像路径
procedure TCameraRollForm.TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap);
begin
{ Assign the image retrieved from the Photo Library to the TImage component. }
imgPhotoLibraryImage.Bitmap.Assign(Image);
end;
有没有办法可以通过 iOS 在服务器上发送位图?