Changing permissions on a File from applicationDataDirectory in Titanium Mobile - file

I'm trying to send a file, as an attachment, via the phone's e-mail client using Titanium Mobile. I've run into a snag where the attachment is sent, but is received as a 0-byte file.
The problem is that the file created in data/data/package/app_appdata is -rw------
From glancing at the Android SDK, this is by design. The app's "private storage" is readable only by the owner of that folder, the running application.
I presume that the Android e-mail client can see that file, but cannot read it.
The full Android SDK mentions a MODE_WORLD_WRITABLE that allows you to keep using the applicationDataDirectory and give all apps permission to read/write that file. Does an equivalent exist in Titanium Mobile?
The other solution is to create a temp file, which unfortunately uses Titanium's own naming scheme (tiXXXXX.txt), or I could write to the "external storage" since it is public (which may not always be available, however.)
This is the call I'm using to get the current file, it can be read within my app just fine, but when I use the addAttachment call of an emailDialog it simply sends a 0 byte file to me.
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "generated_filename.txt")

Have you tried using tempDirectory instead. I'm of course assuming once the file is emailed you don't need to keep it as the applicationDataDirectory is fully backed up and usually used to store data the app retains.
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Filesystem.tempDirectory-property.html

Related

how to read data from a properties file in reactjs

I have created properties file in other directory of my computer. I want to read the data from that file and display it. So can anyone please suggest me, How can I achieve this.Thanks in advance.
From what i understand, you have a properties file on YOUR computer and you want to read that file from reactjs app. This is not possible as front end is not allowed to directly access user's hard disk. This would be a big security flaw. This is because the front end part runs on the client side.
Consider a situation where you have written code to read file from desktop. Then your app would be able to read the desktop files of ALL USERS who use that app. That's why you always see an upload button when you have to choose a file to read. The file is first sent to server side and then processed.
Since reactjs runs on client side, it is better to maintain a server and make an API call to it to fetch the data. Or you can hard code it in react app itself if it isn't sensitive info.
On front-end side - You can't and You should not be able to because it'd be a huge security risk. Do not try to solve it on the client side. Try to think about a back-end solution after uploading that particular file to the server.
On the other hand - why are you trying to keep a file, which is logically connected with the app - outside of the repository ?
Since its not clear what you are trying to achive,
Situation 1. You developed a react app for users, which is trying to read a user's file on his computer.
This is not possible as reactjs is a front-end library which can access the resources limited to browser only. You just can't read someone else's files.
Situation 2. The file is a part of you project which is in different directory.
So just put your file inside the your project directory, and since it is a properties file then this is how you can import it inside your project.

How can I dynamically use images outside of my reactjs project?

I am developing a client-only ReactJS application (only for local usage) where I need to save and load images by filepaths (URL and local file system).
The paths are stored in the local storage and images from URLs can be used. Anyway, local images cannot since ReactJS is using the project directory and I cannot escape it.
Is there the possibility to open files with absolute path from the local file system or can I/do I have to upload it in the project directory?
Are you running this through a browser? If so Javascript on browsers does not yet have the ability to access local file systems. I haven't tried this but you could run Node locally and use ExpressJs for client-server communication.
As stated here:
you'll need two pieces:
A browser piece, which does the UI with the user.
A Node piece, which runs on the user's machine (and thus can access the file system) and which the browser piece uses to do the actual file operations.
Probably the easiest way for the pieces to interact would be HTTP, which you can trivially support using ExpressJS.
So for instance, if the user wants to delete a file:
User clicks something to say "delete this file"
Browser JavaScript sends the command to the Node process over HTTP via ajax
Node process does the deletion and reports success/failure
Browser JavaScript displays the result

The name of a created PDF is not transferred from the server to the client (GWT - GAE)

I develope a GWT-application which creates a PDF-file at the server, and then transferres it to the client.
At the client-side, a window appears which allows the user either to
open it with a program assigned to the file name ending, or
save it to disc.
I have read several threads to this topic, such as
How can a user download a file in client side (Google Web Toolkit)
GWT: Showing PDF created as POST response
How can a user download a file in client side (Google Web Toolkit)
and that helped me coding the doGet()-methode in my print-servlet like this:
resp.setContentType("application/octet-stream");
resp.setHeader("Content-Disposition:", "attachment; filename=\"" + fileName + "\"");
This works fine when testing and debugging using the local GWT-developement server.
But my big problem is:
After deploying to GAE and running the code on GAE, the created pdf-name is not transferred to the client...!
Instead of e.g. TestPdf-25072016.pdf, the name only consists of the word print.
This leads to the fact that the standard-program for a PDF is not invoked automatically when I want to open it. And, of course, print is not the name of the PDF I want to have...
Where is my failure? Especially I am confused that everything works fine when using the local developement server?
Thanks a lot for your support!
You could use a tool like Wireshark or Fiddler to capture the actual HTTP header sent to you when you call printing in GAE.
Maybe GAE is adjusting the header or just blocking it.

What to use instead of IAuthenticator (read/write file via winforms to Google Drive)

I am trying to write/read files to Google Drive from a Winforms app. I've taken some of the sample code from projects Google has provided, but they all use IAuthenticator, which is no longer valid, from what I read.
I can do almost everything I need, except actually read the file (that I wrote) back from Google Drive, because I cannot figure out how to authenticate. Saying another way, I can read the file metadata back, but need to authenticate before I use the DownloadUrl to read the file contents. I cannot figure out how to get past Authentication. Can anyone help?
Thank you

Upload local database to SkyDrive as a textfile

I havent looked at the samples yet for the SkyDrive.
I have done a application that saves some data in a local database on the phone.
What i want to do is to upload all these to a SkyDrive account as a textfile.
Is this possible?
Might want to start with a blog post I wrote - Adding SkyDrive support to your Windows Phone application. You will need to download the Live SDK (unless you want to use the REST API manually, which I can see no reason for at this point).
Uploading is fairly simple after that, given that you obtained the proper session init:
client = new LiveConnectClient(App.MicrosoftAccountSession);
client.UploadCompleted += MicrosoftAccountClient_UploadCompleted;
client.UploadProgressChanged += MicrosoftAccountClient_UploadProgressChanged;
client.UploadAsync("me/skydrive", Binder.Instance.CurrentlyUploading,
stream, OverwriteOption.Overwrite);
Where stream is a MemoryStream instance.

Resources