File upload with NSURLRequest fails
I'm trying to upload a file with the NSURL* API, but on the server end the PHP code is unable to decode the $_FILES array. The PHP code works fine when posted from an HTML form (and from clients on other platforms). Traffic sniffed on the wire looks good as far as I can tell, so what would be the problem? The code in question follows. NSString *urlString = @"http://server:8080/php/post.php";; NSURL *url = [NSURL URLWithString:urlString]; NSString *requestMethod = @"POST"; NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; [req setHTTPMethod:requestMethod]; NSString *headerFieldName; NSString *headerFieldValue; NSString *boundary = @"-1234567890"; headerFieldName = @"Content-Type"; headerFieldValue = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; [req addValue:headerFieldValue forHTTPHeaderField:headerFieldName]; NSString *phone = @"7195554321"; NSDate *currentDate = [NSDate date]; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@"MMddHHmmss"]; NSString *dateString = [dateFormatter stringFromDate:currentDate]; // Will look something like this: form-data; name="file"; filename="7195554321_1_20080311132327_jpg" headerFieldValue = [NSString stringWithFormat:@"form-data; name=\"file\"; filename=\"[EMAIL PROTECTED]@_jpg\"", phone, dateString]; NSMutableData *postBody = [NSMutableData data]; // Add boundary [postBody appendData:[[NSString stringWithFormat:@"[EMAIL PROTECTED]", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; // Add form-data with filename [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: [EMAIL PROTECTED]", headerFieldValue] dataUsingEncoding:NSUTF8StringEncoding]]; // Add content-type [postBody appendData:[[NSString stringWithString:@"Content-Type: null\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; // Add image data [postBody appendData:imageData]; // Add boundary-- [postBody appendData:[[NSString stringWithFormat:@"[EMAIL PROTECTED]", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [req setHTTPBody:postBody]; NSHTTPURLResponse *res = nil; NSError *err = nil; NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&res error:&err]; -- Tom Harrington [EMAIL PROTECTED] AIM: atomicbird1 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: File upload with NSURLRequest fails
On Thu, Mar 13, 2008 at 2:50 PM, Tom Harrington <[EMAIL PROTECTED]> wrote: > [postBody appendData:[[NSString stringWithString:@"Content-Type: > null\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; Someone asked about this. FYI, "null" is what the other clients use, but if I use "image/jpeg" it fails in exactly the same way. -- Tom Harrington [EMAIL PROTECTED] AIM: atomicbird1 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: File upload with NSURLRequest fails
Also, for what it's worth, I can hit the server just fine at the command line with: curl -F "[EMAIL PROTECTED];filename=7195554321_1_20080311132327_jpg" http://server:8080/php/post.php ...yet for some reason the NSURLRequest approach fails. Any/all tips are welcome. On Thu, Mar 13, 2008 at 3:02 PM, Tom Harrington <[EMAIL PROTECTED]> wrote: > On Thu, Mar 13, 2008 at 2:50 PM, Tom Harrington <[EMAIL PROTECTED]> wrote: > > [postBody appendData:[[NSString stringWithString:@"Content-Type: > > null\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; > > Someone asked about this. FYI, "null" is what the other clients use, > but if I use "image/jpeg" it fails in exactly the same way. > > > > -- > Tom Harrington > [EMAIL PROTECTED] > AIM: atomicbird1 > -- Tom Harrington [EMAIL PROTECTED] AIM: atomicbird1 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: File upload with NSURLRequest fails
On Fri, Mar 14, 2008 at 12:43 AM, Ben Lachman <[EMAIL PROTECTED]> wrote: > I do this with a perl script on the back end. My experience was that > its was more cajoling the perl script into working that the PHP side, > but that may be because I'm not much of a perl wizard (maybe only > level 8 or so :-). I found it was important to declare a filename if > you're transferring data like this. After much close looking, someone told me to count the dashes. Turns out I was using the wrong number for my multipart boundaries. The actual boundaries need to have two more dashes than the boundary declaration in the content-type header. Once I fixed that, my code worked. -- Tom Harrington [EMAIL PROTECTED] AIM: atomicbird1 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Adding commandline batch mode to Cocoa app
On Sat, Mar 22, 2008 at 4:26 PM, Carsten <[EMAIL PROTECTED]> wrote: > However, image processing apps can benefit from batch modes, and > although some things can be nicely handled by an in-app batch manager, > the ideal would be to also allow the application to be run from the > commandline, as a traditional unix utility. > > Given the .app bundle format of Cocoa apps, I don't quite see how I > would do this. In main(), I have added an if contingent on the > existence of commandline parameters (which can be refined in case Mac > OS X uses these to launch drag-n-drop scenarios, something which I > don't know yet), which doesn't load the GUI in case the app has been > launched in commandline batch mode, but the executable is deep inside > the .app bundle... > > What is the traditional Mac OS X/Cocoa way of handling such a > scenario, or is it simply not do it like this, and to force the user > to use an in-app batch manager? You could just use the executable in the .app bundle, though it would lead to some very long command lines. For example you can run TextEdit with "/Applications/TextEdit.app/Contents/MacOS/TextEdit". One approach that some apps take is to have a separate command-line tool which could be installed in /usr/local/bin or some other more normal-seeming place. With this approach you'd probably have a regular drag-install app bundle with a menu item to optionally install the command-line tool. Depending on your architecture the command-line tool could be as simple as a symbolic link to the main bundle's binary. Depending on your requirements, you might consider whether the batch-mode processing would be better implemented as an Automator action. -- Tom Harrington [EMAIL PROTECTED] AIM: atomicbird1 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSURLConnection doesn't post
On Thu, Apr 10, 2008 at 6:27 AM, Micha Fuhrmann <[EMAIL PROTECTED]> wrote: > Now if I place a button on my interface and call test everything is fine, > the post is submitted and the delegate method is called. Suffice I call the > test method from another class and nothing gets posted (break points show me > the sendLogs method is indeed called), the didReceiveData method is not > called either. I've looked into adding the NSURLConnection into an array so > it wouldn't be scraped, created a separate send class just for the post etc. > to no avail, I really don't know what I'm doing wrong. When you call -sendLogs from another class, does the run loop have the chance to run, or does the code block, or busy-wait, or something else that might prevent it from running? You'll need a working run loop for NSURLConnection to successfully post the data and call its delegate methods. Also, is it possible that when -sendLogs is called from another class, it's also called from a separate thread? NSURLConnection's delegate methods are called on the same thread that initiated the connection, and if you've started a different thread, you have to create your own run loop. -- Tom Harrington [EMAIL PROTECTED] AIM: atomicbird1 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: System Preferences window is wider in Leopard? How do you make a Tiger compatible UI?
On Wed, Apr 9, 2008 at 11:06 AM, Dave Camp <[EMAIL PROTECTED]> wrote: > After designing the UI for a new System Preferences pane I've discovered > that the window size in Leopard is 75 pixels wider than it was in Tiger or > earlier OS releases. The net result appears to be that my shiny new UI is > clipped on the right side in Tiger. Ugh. I've sent feedback that the docs > are incorrect here and need to be updated... > > In the mean time, what is the correct way to handle this? > > From what I've read on the net adding springs in IB doesn't help. Would it > be safe for me to resize the preferences window to be 75 pixels wider on > Tiger while my pane is visible (and size it back down when my pane is > deselected)? Probably not a good idea. Although the window width differs from Tiger to Leopard, it's not supposed to be a resizable window. If you're going to run on Tiger you'll need to live with the narrower window. I was pretty annoyed when I found out that Leopard's System Preferences wouldn't resize the pref pane view, even if you had designed it to be resizable. But that's the way it is. > Do I have to make my UI narrower and have an obnoxious amount of dead space > around the edges on Leopard? Maybe. You can find out what the current window width is once your preference pane has been loaded into the window. Using something like "[[[self mainView] superview] frame]" would give you the current width, and if desired you could adjust mainView's frame appropriately. This would mean designing to Tiger's pref pane width, and then expanding when running on Leopard. Best to stick with looking up the size instead of the OS version, because who knows what might happen in 10.6? -- Tom Harrington [EMAIL PROTECTED] AIM: atomicbird1 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: NSURLConnection doesn't post
On Fri, Apr 11, 2008 at 3:53 AM, Micha Fuhrmann <[EMAIL PROTECTED]> wrote: > Ok, I've used - (void)performSelectorOnMainThread:(SEL)aSelector > withObject:(id)arg waitUntilDone:(BOOL)wait and it's fine one, you've > pointed t what was wrong, however I thought that because the method sendLogs > was invoqued by an instance that is alive during the whole app lifetime it > would be OK. Turns out that NSURLConnections called indirectly by a short > time run loop to the main thread doesn't follow up. Right, the run loop needs to keep going at least until NSURLConnection is finished. Although secondary threads don't automatically get run loops, it's OK to create new run loops in different threads if it's appropriate to your situation. Using -performSelectorOnMainThread: is one way around the problem, but it might make more sense to just give the thread its own run loop. It all depends on your app architecture. -- Tom Harrington [EMAIL PROTECTED] AIM: atomicbird1 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: [Moderator] List Guidelines - Must Read
On Fri, Jun 27, 2008 at 12:01 AM, Jens Alfke <[EMAIL PROTECTED]> wrote: > On 26 Jun '08, at 11:36 AM, Hamish Allan wrote: > >> What we really need is for the cocoa-dev list admin page to require >> new subscribers to type in the phrase "I will not make posts about the >> iPhone or Snow Leopard" :) > > No, you've bought into the whole reality distortion field. What we _really_ > need is for Apple to allow developer discussion of NDA'ed products. If there > were an *Ph*n* mailing list on this server, and if that list were mentioned > in the SDK or on the *Ph*n* developer home page, people would see it and go > there to post. The list could be set up to require ADC membership to > subscribe, so as to preserve the airtight confidentiality of all details of > the *Ph*n* SDK. Oh, they do allow it, despite what the moderators here say. You just have to use the appropriate Apple forum. Apple's support forums have a "developer" section with no shortage of iPhone discussion. Apple hosts it and nobody seems to mind. See <http://discussions.apple.com/category.jspa?categoryID=164> for the forum. It seems kind of silly that iPhone discussion is forbidden here when Apple's apparently not concerned with hosting the discussions elsewhere, but hey, what do I know about it. -- Tom Harrington [EMAIL PROTECTED] AIM: atomicbird1 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]