Handle files with content - ios

I'd like to give users the chance to import data into my app. The app uses core data and my idea would be that the user prepares a text file and send it as email. In the "Open in..." dialog I like my app to be listed.
The file will be a text file but the content must follow certain rules, so that I'm able to extract the data I need to populate core data entities.
Must I define a custom UTI for that?? (I don't want my app listed for every text file)

Yes you can define a UTI, as well as a MIME type for your format. Give it a unique file extension and the fact that's it's encoded in plain text is not important (HTML, XML, etc. all fall into this category).
You don't specify how complex your text format will be, but if it's complex then you might want to consider using a language parser tool to process it, utilizing bison/flex (yacc/lex), or ANTLR.

Related

Extract text of OneDrive documents using Graph Api

I have been using Ms Graph API, to download the files of OneDrive successfully.
I was looking for a way to read only the text content (for indexing purpose in my application) using Graph API, for different types of files(pdf,xls,zip,Images etc.) instead of going by the conventional approach of downloading the complete file and then extracting the text using some "Text extracting api" and then index the file, which would be a time consuming task. I am aware GraphAPI has its own search features, but it lacks ability to do complicated search like regular expression search (please correct me if I am wrong). I am sure OneDrive does its own indexing for each file which helps a user to do the basic search.
So, is there any way I can get the text content of the documents using the Graph API?
I don't believe getting a 'preview' of text-based documents is currently available through the API. You will need to make a GET request to fetch the content. If you don't want the full document, you can request a partial range of bytes that you believe would be enough for the document. In addition, to make it easier to handle different file types, we currently support converting common file formats to PDF (to possibly standardize your file parsing logic).

Best way to switch languages in the software or website?

I want to know the best programming technique to switch languages in the software or website. So anyone can give me some suggestions? Thanks!
There is no standard. But I used the following technique in websites.
Put all the visible strings (eg. "file", "menu", "contact us") in a file or database. It can be xml, json or any format that you easily parse later. Make sure all the data is saved in different directory/db tables according to locale/language.
Wrap all the strings with a function or static class method. Every time they are displayed they'll go through some processing.
When you first load the software or web determine the locale or language that user wants to use.
According to users choice select the string source. database, filepath etc. For e.g. if user want to see strings in en_GB locale, find strings in en_GB folder or in lang_en_GB table. Naming format is in your hand.
Now each time the function or static class method is called find strings in the source you selected on Step 4.
It depends on the language you are using. Many have built in support for it. In android for example what you do is store all strings into an xml file that is named based on the region. And the operating system will automatically use the appropriate resources based on the phones region.
Look into what support your language/platform includes. You will want to externalize all your string constants such as "Press the menu button" into an external file. Then just get this file translated to each language you want to support, and use the OS to automatically use the correct resource file. Or if the platform/OS does not support such a thing write some code to determine which resource file to use yourself.

How to get text files onto iPhone?

I am making an app where the user will probably want to import a custom settings file.
It is a tuning fork app, and there are more tuning systems in existence than you can shake a stick at. I will supply a settings file that contains maybe half a dozen common tunings. this will satisfy 99% of customers, but those who want to go the extra mile I would like to provide the option of complete customisation.
Now it doesn't make sense to make an elaborate UI design. it would take users hours of painstaking way looking up numbers on Google or using their calculator, and keying in various tuning systems.
also what if they reset their phone?
what if they want to transmit this data to the iPad?
what if they want to send their configuratino to a friend?
what if I am maintaining a wiki which holds 300 different tuning systems, and they would like to grab half a dozen?
the best solution path I can see is to have the user create a text configuration file, with a simple format. something like this:
theme: "A3"
comment: "An octave below concert pitch (ie A4 440Hz)"
presets: {
A3 220Hz=220.0
}
// http://en.wikipedia.org/wiki/Guitar_tuning
theme: "Guitar Standard Tuning"
comment:"EADGBE using 12-TET tuning"
presets {
E2=82.41
A2=110.00
D3=146.83
G3=196.00
B3=246.94
E4=329.63
}
theme: "Bass Guitar Standard Tuning"
comment: "EADG using 12-TET tuning"
presets: {
E1=41.204
A2=55.000
D3=73.416
G3=97.999
}
Question is, how to get this on to their iPhone?
I don't want to rely on iTunes. maybe they will take their phone on holiday with them, and not their computer. maybe they don't even have a Mac, and they don't have iTunes on their PC. maybe they don't have a PC. maybe they just hate iTunes?
I don't have the resources to set up server space and actually host something myself.
first question: does there exists some place on the Internet I can deposit a text file and retrieve it with a minimal URL?
second question: I would also like to provide a mechanism for the user to load the file directly from their computer, ( say for example they are off-line ) -- how to do this?
Making a file in that format seems like an awful lot of hard work for a user.
It also seems like it would be a pretty big headache for you having to parse that data as the user will undoubtably only rarely get the format correct.
If I was designing this app I would make a UI for the settings. By making the UI you decouple the app from a computer completely as you no longer have to make a text file.
The only potential reasonable solution which is not viable as you do not want to set up a web service would be to create a small web front end where a user can edit their pref's through a custom form and then save the results. Then you can serve up the info by giving them a url, but this still seems a lot harder than just doing it on the device.
Remember that you will also have to implement UI anyway or the user will be forced to use a computer to configure their app - which quickly results in your app being canned for an easier alternative.
If this is still a route you wish to continue down then see this post for filetype association:.
If I paste something into Pastie, eg
http://pastie.org/2197740
I can get the raw text back by copying the URL of the ' download ' link.
(NOTE: cannot use the 'raw' link, as that still displays an HTML file containing JavaScript)
EDIT: Using http://min.us you can actually deposit a textfile, and then pass the URL -- which you get by copying the link from the ' download ' button on the page ).
EDIT: gist.github seems to be the perfect tool for this -- you can write a text file in the browser, and save it. and pastes typically persist forever. just need to throw the URL through bit.ly to shorten it.

rails 3: how to add (or perhaps substitute) a text string to an existing PDF document?

Users of our app need to print a PDF document we have pre-created, but have a placeholder string in the PDF template "YOUR_NAME_HERE" be replaced with their name. (Or, alternatively, we could no use a placeholder and add a new string with a certain font/style at a certain X,Y offset.)
Doing full PDF creation is overkill, since ALL we need to do is add their name to the PDF doc.
To make it more fun, we're hosted on Heroku which does not have local file storage, so we need to create the final PDF as something displayed in their browser that can (hopefully) be saved to local disk.
Does anyone know of a technique that would let us easily add (or replace) text to an existing PDF document?
I'm not finding anything for editing PDFs in ruby. I would just look into using something like prawn to generate them, even if that is a bit overkill when only a few words are different between each.
If efficiency is an issue, you could convert the pre-made part into a PNG and then just add the text on top. It feels dirty, but it'd probably be quicker than full generation and I don't know what other options you have, since it doesn't seem like anyone has implemented a true PDF editor in ruby yet.
As far as local storage, keep in mind that you do have write access to tmp/ on Heroku, so you can use that as long as you're only going to use the file during a single request.

How to find out an extension's content type?

Where could I find out the content type for a specific file format/extension?
For example, I know that an mp3 can be one of the following content types:
'application/mp3', 'application/x-mp3', 'audio/mpeg', 'audio/mp3'
What would be the content type for a zip file? Where would I find out that information for other content types?
I need this for purposes of validation with ruby on rail's paperclip plugin.
Thanks!
Update: I just found this and thought it may be useful to other people
I know that an mp3 can be one of the following content types
Only audio/mpeg is valid. The rest are bogus and won't generally work anywhere.
What would be the content type for a zip file?
application/zip.
Where would I find out that information for other content types?
The proper list of all registered media types is at IANA. Of course, there are many more types that have not been registered, largely those with the x prefix.
If you want to find out on the fly what your machine thinks a particular extension is using a server-side script, you can find that in an OS-specific place. On Windows, the file extension/type information is stored in the Registry. On desktop Linux, it's in /usr/share/mime. On an Apache web server, you might want to re-use Apache's mime.types table.
for a specific file format/extension?
File extensions are unstandardised, and not a reliable way of checking the type of a resource on the web, including a file upload. File-extension-to-media-type mappings are an OS/installation-specific issue so you can't know what media type a file is from extension on another machine. Furthermore, some operating systems don't even use file extensions to determine type (or only use them as a fallback).
Even looking at the Content-Type supplied with a file upload is of little use, since it's so often wrong due to bad setup at the client side. I guess this is why the bogus types like application/mp3 have crept into the list above, because some time one browser somewhere on a badly-set-up machine sent the wrong type. But browsers can always send any old wrong type... you're just as likely to get a text/plain MP3.
If you need to allow the user to set a definitive content-type for the uploaded resource, you'll have to let them manually pick it. Of course you can use a bit of script hacking to make useful guesses like “if it ends with .jpeg, it's probably a JPEG” and make that selection automatically. But in the general case it is not reliable to guess type from user-submitted file extension.

Resources