I want the user to select a file from an iPhone and upload to an HTTP server.
Example: The GoodReader application has this feature in it.
How can this be done?
You can't get all the files stored on the phone.
As the comment from Stephen Darlington states, your app is sandboxed and can only get to the files stored inside your app.
You could register your app to be able to open PDF, txt, doc and other files that you are interested in sending to your server and then users would be able to open these documents in your app. Once the files are inside your app you could then use any number of ways to upload them.
Please read the documentation here about registering your app to understand file types:
Registering the File Types Your App Supports
The file list would just be a UITableView, probably with a custom UITableViewCell.
There are a number of options for uploading data to a web service. The built-in way would be to use NSURLConnection. There are some open source frameworks that may be able to help but I have not used them.
The best way that I've found to upload images is to use the ASIHTTPRequest API. Here is a link on the documentation on POSTING data to a server. Download ASIHTTPRequest here and these are the setup instructions.
How to select a file depends on what kind of file you're trying to select. If you're trying to upload images you should look into a UIImagePickerController and UIImagePickerControllerDelegate. If not, you'll have to create a NSFileManager to search through your application's files.
NSFileManager Class reference:
http://developer.apple.com/iphone/library/documentation/cocoa/reference/foundation/Classes/NSFileManager_Class/Reference/Reference.html
Discovering Directory Contents:
– mountedVolumeURLsIncludingResourceValuesForKeys:options:
– contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error:
– contentsOfDirectoryAtPath:error:
– enumeratorAtPath:
– enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:
– subpathsAtPath:
– subpathsOfDirectoryAtPath:error:
Related
There is a very cool iPhone app called Viddy where you can download filters to apply to videos.
How can they pack filters outside the app, and make them available to users via downloading?
One way would be to have an in-app purchase that's just a document that describes an image processing graph. (Think of a nodal graph representation for something like Shake or Nuke.) For example, a glow is often implemented as a blurred image mixed with the original image. You could create a document which describes that processing graph. Once you've downloaded such a document into your app, you can implement it using Core Image filters, or write your own using GLSL, or even just straight CPU processing.
It's pretty simple, they do use shaders and they're downloaded from the internet.
Download iExplorer for Mac, connect your iPhone with Viddy installed.
Check Library/effects folder in Viddy.app. You'll find afx_1_0.xml and vfx_1_0.xml files there.
Download them to your Mac, open them and you'll find filters definitions there along with URL to download them.
An example is SOHO filter. Download this file, open it and you'll see three files there: shader.fx3 where shader is defined, thumb.png for thumbnail and vignette.png file, which is used for this shader as well.
We did use same approach in unnamed application, but we did encrypt all this information along with shaders itself to avoid analysis like this one :)
Encryption, decryption example request in comment
Let's say you have .fx file with your shader (or any other file).
Open Xcode and go to Build Rules where you can define build rule for *.fx files. Set it to run your Custom script: which can look like this one:
ENC_KEY="your-encryption-key"
${PROJECT_DIR}/../Tools/bin/crypt -e -k $ENC_KEY -i ${INPUT_FILE_PATH} \
-o "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${INPUT_FILE_BASE}.cfx"
This script produces .cfx file, which has same content as .fx file, but is encrypted.
crypt binary came from this project: download crypt Xcode project.
Download encrypted resource demo.
Copy EncryptedFileURLProtocol.* and NSURL+EncryptedFileURLProtocol.* files into your project.
In app delegate call this to register your protocol [NSURLProtocol registerClass:[EncryptedFileURLProtocol class]];
And now when you do want to open encrypted resource, you have to use protocol encrypted-file instead of file://. This task handles NSURL category from demo project and you can simply use [NSURL encryptedFileURLWithPath:#"/path/to/my/encrypted/file"].
It's pretty simple and you'll find most info you need in sample app (link above). Also you can mangle your encryption / decryption key in application, so, people have to think and the key is not easily readable. Now, when you access encrypted file via this NSURL, it's automatically decrypted for you in app. The decryption key is set in sharedKey in EncryptedFileURLProtocol.m file.
The easiest way to do this is to build the filters into the app itself, and have the in-app purchase simply unlock the ability to use them.
If you wanted to avoid the download time for all the additional images or other pieces needed, you could still include the code in the main app, and just download the extra resources needed. You can use something like Urban Airship's IAP support to host & download the IAP resources. (You might also want to look into new features of iOS 6 in this vein.)
GLSL shaders may be downloaded in source code form and then to be used for processing. It gives very flexible way to create new filters after having app published. From another hand it might be enough just to update (download) additional filter data. For example, Instagram uses same color curve technique for most filters but with different curve data, so it they want, they will be able to update their filters online.
Filter for videos also uses CIImage class like intagram application for images. See the link here:"http://www.icapps.be/face-detection-with-core-image-on-live-video/". Now filters can be download the filter (actually its In App Purchase happening).
Put the purchase/download method right beneath the case:
case SKPaymentTransactionStatePurchased:
[self ...];
so whats happening is purchase of filter for free which can be used on any video. Actually method is enabled to have filter after SKPaymentTransactionStatePurchased.
I have an app I'm designing that will allow for lots of PDF viewing. There are a lot of different languages available, and so if I were to include all of them in the app, it would be like 100+ mb in size which just won't fly.
So I'm thinking that I am going to put the pdf's on my server, and access them with a direct download link like this:
http://mysite.com/pdfs/thepdf.pdf
Which will return the exact pdf I want. So I'm wondering how I can go about accessing these resources as I download them on the fly?
I imagine I need to save the pdf's to the app resources folder? And then when a tableView row for the pdf is selected, I check if the pdf is in the resources folder (how do I do that?), and if not, pull it down off the server, and load it into my view?
I think I have an okay idea of what I need to do, just not very clear on the code to do it. Can anybody post the code for accessing the resources folder (if that's actually what I need to be doing), and maybe the code for how to check if something is in the resources folder?
Thanks!
Have you considered using a UIWebView to view the PDF instead of downloading and loading it yourself? UIWebView should take care of caching, so you won't have to worry about that.
Assuming that a UIWebView won't work, to download PDFs and see if they exist, you need to store it in the Documents folder. The resources folder cannot be altered after you submit your app to Apple, but the Documents folder in your app is completely fine. To access it, I would actually recommend ConciseKit, which can be found on GitHub. It gives you a helper method to access your app's document directory. The helper method is
[$ documentPath];
Then you can get the path for a file by doing
[[$ documentPath] stringByAppendingPathComponent:#"file.pdf"];
So that is how you get a path to a file, to check if it exists, you want to use NSFileManager.
[[NSFileManager defaultManager] fileExistsAtPath:#"path from above"];
I have an app which is similar to an FTP client. I can download various types of documents in it. (DOC, XLS, PDF, PPT etc)
Now, I want to read those documents in another application. For example: Suppose I download a PDF in my app, it is possible to read from AirSharing or File Magnet?
I don't think it's possible for other applications to access Library folders owned by other apps, and definitely not private application folders.
Document handling might handle what you want only to an extent - not the files that don't have their types registered to any app, and only at a one by one file basis, essentially duplicating the files as well.
If this is your app you are talking about, you can implement the Open In feature which is part of the Document Interaction in iOS, which will allow the user to access the file in any app that is registered to handle the extension/UTI.
In particular, these methods:
UIDocumentInteractionController
– presentOpenInMenuFromRect:inView:animated:
– presentOpenInMenuFromBarButtonItem:animated:
i am making an app in which i have to upload an image/video file to the server...i want to know what things i needed to do this..?and i also have to show the progress bar while image is uploading...how can i do this..?
can you write some code snippet on how to upload file to server...?
If you are using http to transfer files.Allseeing-i have a great api for this called ASIHTTPRequest, its feature rich, well documented, easy to use and it supports file transfer tracking.
They have code examples and a description on how to include it in your projects.
In my application, i am trying to find all files of particular extension (like .pdf, .txt, etc) that are stored in the device (either downloaded or transferred from system) and want to list them in table View. Is it possible to do so and if it is then can i associate file of specific extension to get it open in supporting application (any third party plug-ins).I went through numerous documentation but couldn't find the solution. Also how can i index files of these extension for fast search.
Any help is appreciated. Thanks.
No, it's not possible. You app can't access files of other apps directly.