rails:上传图片时ios中的服务器内部错误

时间:2015-08-06 09:23:53

标签: ios ruby-on-rails image upload

当我将图像文件上传到rails webrick server时,会出现内部错误“找不到临时目录”,并且没有接收请求。

boundary = @"---------------------------14737809831466499882746641449";

NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"nickname\"\r\n\r\n%@\r\n", nickname] dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: attachment; name=\"profile_image\"; filename=\"%@\"\r\n", @"19"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:UIImageJPEGRepresentation(profileImage, 1.0f)];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];


NSString *requestURL = @"http://0.0.0.0:3000/index";

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
NSString *contentLength = [NSString stringWithFormat:@"%lu", (unsigned long)[body length]];
[request setURL:[NSURL URLWithString:requestURL]];
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];
[request setValue:contentLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:body];

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

[connection start];

1 个答案:

答案 0 :(得分:0)

自我解决。

默认/ tmp目录权限是drwxrwxrwt。

但我更改了drwxrwxrwx的许可。

所以 - > sudo chmod o + t / tmp

清楚。