Android Question [solved] send file and delete it

sirjo66

Well-Known Member
Licensed User
Longtime User
I have an app with HTTP server service

When the customer ask for a file, the app send this file (is a JPG file) and then the app delete this file on the device.

All works fine on many devices, but on a device these lines fault:
B4X:
' send the file
Response.SetContentType("image/jpeg")
Response.SendFile(File.DirDefaultExternal, FileNameToSend)
' delete the file
File.Delete(File.DirDefaultExternal, FileNameToSend)

My image appeare right for the 90% of the image, and the last lineas on image are all grey.

This because, while the system is sending the image, it are deleted !
If I delete the line
B4X:
File.Delete(File.DirDefaultExternal, FileNameToSend)
it works fine

How can I do ?
I want to delete the file when the system has finished to send the file, so the file is uploaded right.

Many thanks
Sergio
 

DonManfred

Expert
Licensed User
Longtime User
Wait for Jobdone raise and delete the file only if job.success = true.
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
I'm sorry, I am a newbie :(

I thinked that JobDone is an Event for HTTP client, is it also for HTTP server ??

My code:
B4X:
Private server As HttpServer
....
server.Initialize("Server")
server.Start(port)
....
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)
....
End Sub

How can I create event for JobDone ??

But JobDone if only for HttpJob or also for HttpServer ??

Thanks
Sergio
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
OK, many thanks for the answer.
I solved it by changing the protocol (client and server are my programs).
Now, the client first send a request for to read the file, read and save it, and then the client send another request for to delete the file.
So the server app works right !!

Sergio
 
Upvote 0
Top