0
我使用DropBox的核心API的OAuth 2.0認證,我試圖上傳的UIImage通過它的核心API圖片上傳到DropBox的服務器核心API送禮者錯誤的iOS
https://api-content.dropbox.com/1/files//
在https://www.dropbox.com/developers/core/docs發現( /文件(POST))
我的代碼是
-(void)uploadData:(NSData *)imageAsData and:(NSString *)fileName{
NSString *urlString=[NSString stringWithFormat:@"https://api-content.dropbox.com/1/files/dropbox/Apps?access_token=%@",dropBoxToken];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: attachment; name=\"attachement\"; filename=\"%@\";",fileName] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageAsData]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"returnString=%@",returnString);
其中imageAsData的圖像和文件名的NSData的是「abc.jp G」。 returnString的
輸出爲{「錯誤」:「文件的參數值‘無’是無效的」}
我不知道爲什麼會出現這個問題,請幫助我。
按預期工作。非常感謝您節省了我的時間。 –