简体   繁体   English

当我从另一个 url 下载图像时,将图像上传到特定 url 的正确方法是什么?

[英]what is the correct way of uploading image to a specific url when i am downloading a image from a another url?

I am successfully completed 75% of my task.The main problem is image uploading.我已经成功完成了 75% 的任务。主要问题是图片上传。 Connection is established.but encoding data cannot be uploaded.here i am writing my code like this way连接已建立。但无法上传编码数据。这里我是这样写代码的

UIImage *naveen = [UIImage  imageWithData: [NSData dataWithContentsOfURL:[NSURL  

URLWithString:@"http://www.watblog.com/wp-content/uploads/2011/11/b.jpg"]]];

myimages.image=naveen; 

by using the above code i load the image very successfully.通过使用上面的代码,我非常成功地加载了图像。

the above code i write in did load method.我写的上面的代码确实加载了方法。

After that i take an IBAction in that i write below code之后我采取了 IBAction,我写了下面的代码

NSData *imageData = UIImageJPEGRepresentation(myimages.image, 90);

NSString *encodedImage = [Base64 encode:imageData];

NSLog(@"my encoded image is 6666%@",encodedImage);

//here i am getting encoded image data //这里我正在获取编码图像数据

it is also successful它也成功了

NSString *urlString = @"http://192.168.1.105:9966/PC/store";


NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];

    [request setURL:[NSURL URLWithString:urlString]];

    [request setHTTPMethod:@"POST"];


NSString *boundary = [NSString stringWithString:@"--------------------------

-14737809831466499882746641449"];

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; 

boundary=%@",boundary];


[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

 NSMutableData *body = [NSMutableData data];

[body appendData:[[NSString stringWithFormat:@"rn--%@rn",boundary] 

dataUsingEncoding:NSUTF8StringEncoding]];


  [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; 

name=\"encodedImage\"; filename=\"http://www.watblog.com/wp-

content/uploads/2011/11/b.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];


[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-streamrnrn"] 

dataUsingEncoding:NSUTF8StringEncoding]];

    [body appendData:[NSData dataWithData:imageData]];

    [body appendData:[[NSString stringWithFormat:@"rn--%@--rn",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);

}

whenever i execute the above code the return string is每当我执行上面的代码时,返回字符串是

final[3077:f803]决赛[3077:f803]

html>Apache Tomcat/6.0.35 - Error report html>Apache Tomcat/6.0.35 - 错误报告

family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2

{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}

H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font- H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-

size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B大小:14px;} 主体 {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B

{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font- {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-

family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color: family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color:

black;}A.name {color: black;}HR {color: #525D76;}-->黑色;}A.name {颜色:黑色;}HR {颜色:#525D76;}-->

HTTP Status HTTP状态

404 - /PC/store 404 - /电脑/商店

type Status report类型状态报告

message /PC/store消息/PC/商店

description The requested resource描述请求的资源

(/PC/store) is not available. (/PC/store) 不可用。

Apache Apache

Tomcat/6.0.35汤姆猫/6.0.35

please anybody help me how to pass my encoded data请任何人帮助我如何传递我的编码数据

I am beginner to iPhone programming我是 iPhone 编程的初学者

That seems more like a problem with backend server.这似乎更像是后端服务器的问题。 Try to upload file with any other method - ie from simple HTML form.尝试使用任何其他方法上传文件 - 即从简单的 HTML 表单。

This may not be a clue, but why you're using full URL for a filename?这可能不是线索,但为什么要使用完整的 URL 作为文件名?

[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"encodedImage\"; filename=\"http://www.watblog.com/wp-content/uploads/2011/11/b.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM