0

Im working on Delphi XE5 for uploading a file on a server. Im using a php script to upload the file on the server in a directory,its working fine. the code is

Delphi code

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 code

 < ?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';   }
 }

This works fine on windows as i can use Topendialog and send the path Params.AddFile('file',sfilepath , 'image/jpg');

but how to do this in iOS? i want to browse the image(or any file) and get its path to send it as an argument in Function Upload(sfilepath : string) : string; ?

The samples from \RAD Studio\12.0\Samples\MobileCodeSnippets\CameraRoll doesnt give me the image path

procedure TCameraRollForm.TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap);
 begin
  { Assign the image retrieved from the Photo Library to the TImage component. }
  imgPhotoLibraryImage.Bitmap.Assign(Image);
 end;

Is there a way i can send the bitmap on the server via iOS ?

psqluser
  • 103
  • 1
  • 2
  • 10
  • 1
    Well, your problem has nothing to do with sending the picture, nor anything to do with your server or PHP. Your problem is how to browse for pictures via iOS correct? – Jerry Dodge Nov 23 '13 at 21:08
  • 3
    For file locations on various target platforms, and the functionality in `IOUtils.TPath` that locates them, I'd suggest you [start here](http://docwiki.embarcadero.com/RADStudio/XE5/en/Standard_RTL_Path_Functions_across_the_Supported_Target_Platforms) – Ken White Nov 23 '13 at 22:24
  • Also, see [this related question about TOpenDialog on Android](http://stackoverflow.com/a/19841240/62576). I don't think iOS supports a standard open dialog either. – Ken White Nov 23 '13 at 22:28
  • I've never seen any standardized file selector on iOS, other than in iOS its self. Otherwise, all other apps seem to have their own. – Jerry Dodge Nov 24 '13 at 00:38
  • 1
    @psqluser I suggest you edit your question and remove all the stuff related to your server uploading and change it to ask your ultimate goal of selecting the picture to be sent. – Jerry Dodge Nov 24 '13 at 02:23
  • Do you want the user to select from the Photos library? – Marcus Adams Nov 24 '13 at 15:02
  • @JerryDodge Yes, i want the path of the image – psqluser Nov 25 '13 at 07:10
  • @KenWhite : `Device: This function returns an empty string as this directory is currently not supported` on the site you mentioned..so we cant have the path at all ? – psqluser Nov 26 '13 at 05:33
  • @MarcusAdams : i want the user to select photos from the phone (Camera roll) and get the path of the image selected. – psqluser Nov 26 '13 at 05:39
  • Yes, that appears to be what it's saying, unless you can locate a way using the OS functionality that FMX doesn't wrap. I'd suspect it's not that straightforward, or they would have done so. – Ken White Nov 26 '13 at 15:02

0 Answers0