KimHJ 2 Posted Friday at 03:29 AM (edited) I'm creating an application for a android device were the user takes a picture and it is store on a local network drive. After taking the picture I tried this , but it keeps saying that the path doesn't exist. I was looking around but I haven't fund any thing similar, the Google AI suggested that I use the Android Api contentResolver, but I'm unable locate that unit. procedure TMainForm.Button2Click(Sender: TObject); var PicPath: String; begin PicPath := '\\SERVER\CSPictures'; try if DirectoryExists(PicPath) then Image1.Bitmap.SaveToFile(PicPath + '\' + Edit1.Text + '.jpg') else ShowMessage('Can not find path ' + PicPath); except on E: Exception do ShowMessage('Unable to save picture to' + PicPath); end; end; Thanks for any help. Edited Friday at 03:29 AM by KimHJ Share this post Link to post
Dave Nottage 554 Posted Friday at 06:24 AM 2 hours ago, KimHJ said: Google AI suggested that I use the Android Api contentResolver Is there some reason why you haven't included here what it suggested? 2 hours ago, KimHJ said: but I'm unable locate that unit. You can access the ContentResolver via: TAndroidHelper.Context.getContentResolver, by including the Androidapi.Helpers unit. Regardless, I expect you'll need to use a library such as smbj to access files via Windows shares, which means either finding a Delphi implementation or creating imports and writing the code yourself that uses smbj (or some other library that does the same thing). Share this post Link to post
KimHJ 2 Posted yesterday at 04:17 AM If I have an Apache running on the computer could I use TNethttpClient? I have another Delphi/Android app that retrieves bitmaps from a Windows Server in the cloud using TNethttpClient, I know how to do that part. I will have to find out how to create a conf file to go to a specific path. Share this post Link to post
KimHJ 2 Posted 20 hours ago I got it to work with Apache. I had to add android:usesCleartextTraffic="true" in the manifest to be able to save and load with http, since the local machine don't have a SSL. Share this post Link to post
KimHJ 2 Posted 19 hours ago I was to quick in saying that I had it. Loading an image a display it is working. I'm doing something wrong when I save, if I add a name to the URL like url := 'http://192.168.1.150/test1234.png' I get an error that path is not found. If I create a png file in the folder with that name I get no errors, but the image is not updated. I assume I have to name the Image first and the save it, but I don't see any option in TImage to assign a name to the bitmap, the image comes from the camera. Here is my code. procedure TMainForm.SaveImageToURL(const S: String); var ms : TMemoryStream; httpCli : TNetHTTPClient; resp : IHTTPResponse; url : String; Image: TBitmap; begin httpCli := TNetHTTPClient.Create(nil); try httpCli.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0'; ms := TMemoryStream.Create(); try url := 'http://192.168.1.151/Test1234.png'; Image := TBitmap.Create; try ms.Seek(0,0); Image := Image1.Bitmap; Image.SaveToStream(ms); finally Image.Free; end; resp := httpCli.Post(url, ms); if resp.StatusCode <> 200 then Showmessage(Format('HTTP Error=%d %s', [resp.StatusCode, resp.StatusText])) finally ms.Free; end; finally httpCli.Free; end; end; Share this post Link to post
Olli73 4 Posted 10 hours ago What did you install / configure on Apache server side to accept uploading files? Share this post Link to post