Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective-C Box 2.0 File Upload - Problems
    text
    copied!<p>I've been trying to get file upload working with Box for the past few days. I know I'm doing something wrong, but just can't see what it is.</p> <p>I've reduced my code down as much as I possibly can, to just this:</p> <pre><code>// Configure the request NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:@"https://api.box.com/2.0/files/data"]]; [request setHTTPMethod:@"POST"]; [request setValue:boxAuthString forHTTPHeaderField:@"Authorization"]; // Setu up the request NSString *boundary = [NSString stringWithString:@"--PLEASEHELPMEGETTHISWORKING"]; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@\r\n",boundary]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; NSMutableData *body = [NSMutableData data]; // Add the info and data for the file. [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:@"Content-Disposition:form-data;name=\"filename\";filename=\"testfile.txt\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:@"Content-Type:text/plain\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:@"Hello"] dataUsingEncoding:NSUTF8StringEncoding]]; // Add the info and data for the target folder. [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:@"Content-Disposition:form-data;name=\"folder_id\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:@"0"] dataUsingEncoding:NSASCIIStringEncoding]]; // Close the body and set to the request [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding: NSUTF8StringEncoding]]; [request setHTTPBody:body]; // now lets make the connection to the web NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSLog(@"%@", returnString); </code></pre> <p>But, I still get a return of: {"type":"error","status":404,"code":"not_found","help_url":"http://developers.box.com/docs/#errors","message":"Not Found","request_id":"10130600215xxxxxxxxxxx"}</p> <p>Please can someone help point me in the right direction, as when I use POSTMAN or cURL, I can get it to work - so it is obviously an issue with my code. I suspect it is something to do with the 'folder_id', but can't seem to diagnose the actual cause.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload