How to set file name to NSData before uploading to server - ios

I am currently making an app which converts an NSDictionary into a JSON file, in the intention of uploading it to a server. My issue is, is that I have no idea (let alone control) over what the name of the uploaded file is, how do I change/modify it?
Cheers,
Seb OH

This is something that should be handled by whatever FTP client library you are using.
For instance, FTPManager on GitHub (https://github.com/nkreipke/FTPManager) has the following method:
- (BOOL) uploadData:(NSData*)data withFileName:(NSString *)fileName toServer:(FMServer*)server;
That looks like it will fit your need just fine.

Related

Dropbox SDK bug

I was found something strange when I using Dropbox SDK 1.3.14
And here is how the bug happen , I put a dictionary tree like
/Comic/Author - Comic name (ex.浦澤直樹 - Monster)/Volume1/0.jpg , 1.jpg , ...)
And I want download the jpg to iOS app,And also create the same dictionary tree as Dropbox
So I create a dictionary tree in Document , It looks like
/var/mobile/Containers/Data/Application/12711FE6...290C7EAF50/Documents/Dropbox/Comic/浦澤直樹 - Monster/Volume1
Than I try to download the first page of comic
But it shows an error tell me the dictionary is not exist .
I use NSFileManager to check , It did exist .
Finally I find the problem
At this callback
- (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata {
for (DBMetadata *file in metadata.contents) {
NSLog(#"File Path : %#",file.path);
}
}
Path will print like this
1./Comic
2./Comic/浦澤直樹 - Monster
3./Comic/浦澤直樹 - Monster/Volume1
4./Comic/浦澤直樹 - monster/Volume1/0.jpg
Now at the last file path , it gives me a different path name
I don't know why , but if I use this path to check is the parent dictionary is ready , It will return false.
So I never can download the file to specified path success
I was wonder does anyone got same issue like me ?
Dropbox itself is case-insensitive, with attempts to be case-preserving. However, due to various specifics, the API can't always return the expected case for every path component. So, for any file or folder metadata, the filename/last path component should have the preserved case, but other path components are not guaranteed to.
We realize this is non-ideal of course and are looking into ways to improve it, but I don't have a solution to offer right now.
If you need the preserved casing, you'll need to build it up from the last component in each parent entry.

ios share extension - files from dropbox not loading correctly

When I try to load a shared item, the data that comes back is dropbox's login page - as if I weren't authenticated.
Here is the current method I am using to get the file data:
[itemProvider loadItemForTypeIdentifier:docType options:nil completionHandler:^(NSURL *url, NSError *error) {
//my code
}];
doctype is an appropriate kUTType like kUTTypeImage or kUTTypeText, for example. The mimeType that we write the file with is correct to, per other files. It's the actual content loaded from dropbox (just a login page every time).
I have used other variations of the method (UIImage *, and NSData *) but get the same result for dropbox files.
Our shared extension works fine with files that are downloaded in apps like goodreader or Files. The problem arises when I try to share a file from the dropbox app. It gives me a url that I can put into any browser and it will take me to the file, so the url is not the problem.
Has anyone else faced this?
Here is an example link to a document that does this:
https://www.dropbox.com/s/qxkd1957qf7iq9x/04%20-%20Test%20Document.doc?dl=0
Thank you for your help on this Greg. I found that this worked instead by just changing the url and setting dl=1 like so
From:
https://www.dropbox.com/s/qxkd1957qf7iq9x/04%20-%20Test%20Document.doc?dl=0
To https://www.dropbox.com/s/qxkd1957qf7iq9x/04%20-%20Test%20Document.doc?dl=1

Steps to get the list of pdf files from FTP in IOS

I'm new to IOS Development. This is the first time i'm hearing about FTP in IOS .I'm not getting, How to proceed further . I got this code https://developer.apple.com/library/ios/samplecode/SimpleFTPSample/Introduction/Intro.html .
But i didn't understand from this code .
I need to list the pdf files and folders from FTP . First i don't know how to establish the connection to FTP . Can any one please help me with steps.
I fyou look in ListController.m, listOrCancelAction is called when you click on List button.
In turn if you put a break point in startReceive you would see that
CFReadStreamCreateWithFTPURL is opening a "Open a CFFTPStream for the URL" with a specified URL.
I suggest you put a couple more break points and step through the code?
NSStreamDelegate is being used as callbacks when something is happening in particular
- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
is called when connection is open or data is received.
Hope this is enough to get you started.
entryToAdd = [self entryByReencodingNameInEntry:(__bridge NSDictionary *) thisEntry encoding:NSUTF8StringEncoding];
in parseListData will have file name in kCFFTPResourceName which of course you can parse to find out if it is a PDF file. You may look at kCFFTPResourceType to see if you can use to determine file type, not sure.

FTP for iOS, how to download from FTP protocol?

I have been using SampleFTP from Apple but I cannot understand the procedure, I mean, in other languages is simple as set the URL, Path, user and password then "navigate" and download or upload things to that Path... but I don't understand how to do in iOS... I don't have any NSFtp or whatever...
EDIT:
From the begining my #import "NetworkManager.h" does not work, error.
Can Use https://github.com/erica/iphone-3.0-cookbook-/tree/master/C13-Networking/15-FTP%20Helper
and
- (void) download
{
NSData *ftpData = [NSData dataWithContentsOfFile:[FTPHelper sharedInstance].filePath];
}
There is also the Karelia ConnectionKit. Free. Open Source and under active development.
There is no FTP inbuilt library for iOS,but you can find custom librariews for that like tihis one http://code.google.com/p/ios-ftp-server/ or http://www.chilkatsoft.com/ftp-objc.asp

CocoaHTTPServer on iOS: set up server so user can download NSData as file

I want to make the following webpage using CocoaHTTPServer: there should be a link to download a file, but the source file must be NSData object in memory.
As far as I see in samples, there is an easy way to link some file on iPhone to the hyperlink. Is it possible to "link" NSData?
Would be very thankful for examples.
All you need to do is to return HTTPDataResponse in your HTTPConnection subclass.
If you want an example have a look at the CocoaHTTPServer sample called DynamicServer and replace - httpResponseForMethod: URI: in MyHTTPConnection with something similar to the following:
- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
{
// Before returning you can analyze the passed path argument and select the correct data object to return...
return [[HTTPDataResponse alloc] initWithData:placeYourDataInstanceHere];
}

Resources