Picture of Wim 4127
Registered 6 years 252 days
Wim 4127 Thursday, 23 December 2021, 01:03 PM
Where should an app write files? FileWriter returns error
Our app should temporarily store files on disk and convert them. This works on our IP4xx but on one our IPVA installations it fails (even though the code is the same).

The app just writes a file to disk to convert, nothing special. But on the IPVA, the error is returned the filewriter does not have permissions.

12-23 11:13:01.161 FileTransferCache@xqting.com I> Got binary file of 154062 bytes 
12-23 11:13:01.161 FileTransferCache@xqting.com FileSystem::OpenWriteFile fileName:test.mp3 append:0 
12-23 11:13:01.161 FileTransferCache@xqting.com FileWrite(01032130)::FileWrite filenamePath:test.mp3 append:0 fopen() failed (13 : Permission denied) 
12-23 11:13:01.161 FileTransferCache@xqting.com E> Failed to create an Innovaphone writer for file test.mp3

Questions:
- To which directory does one write if you just write a file with a filename without specifying any directory? (like in the above example)
- Is this always the same directory? Or is this dependent on environmental things, such as the current working directory that might change in the course of process execution, maybe caused by something else?
- Why do I get an error in this case, and not in other cases/installations?
- Is there a path where the app (instance) can write to so that it works guaranteed. As mentioned, these are only temporary files for conversion, so they are deleted as well at the end of the process. Is there something like a temp directory that we can use for this and that is accessible. This should be available without us having to change file/folder permissions on the OS.

Please advise

Wim


Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 121 days
Daniel Deterding (innovaphone) Thursday, 23 December 2021, 01:25 PM
Re: Where should an app write files? FileWriter returns error
Hi Wim,

as an App Service can have multiple instances, it is not safe to just write a file test.mp3, which would use the current working folder of the app service binary (which you already noticed is undefined and cannot be used).

The SDK provides a temp files mechanism which can be safely used for this purpose:

https://sdk.innovaphone.com/13r2/sdk/common/interface/files.htm

If an instance is started through the AP Manager (note that this might not work while debugging by running the App through Visual Studio!), the AP Manager creates a temporary directory for this instance (databasename.temp inside /app/appserviceid/) and ITempFiles uses this directory to write/read files.
If an instance is stopped, the AP Manager deletes the directory, so that an App doesn't need to take care of this.

Greetings,
Daniel
Picture of Wim 4127
Registered 6 years 252 days
Wim 4127 Friday, 24 December 2021, 01:10 PM
Re: Where should an app write files? FileWriter returns error
Hi,

thx for the suggestion, but, the async API you mention is a lot less nice to use than the file.htm functions that are also provided (they are equal to the common way of working with files). However, thank you for pointing out the working with the temp directory. I now solved it by working with a temp directory as you mention, but, using the file functions to make paths and write to that directory myself... which works perfectly it seems.

- Yes I know there is chance two people work with the same file at the same time, but that chance is so small in our situation, that we do not take it into account (and even then generating a unique filename/path ourselves is still more easy to do).

- Deleting the files only when the instance stops is not really good enough, since an app instance is intended to "run forever" in my opinion, so a lot of files can potentially stay there until the instance stops. We clean up our own mess when we are done with the temp files so disk space is available again for others.

Anyway, problem solve and thx for the suggestion

Kind regards,

Wim
← You can define your color theme preference here