iPhone – 如何将图像发布到Web服务器

iPhone – 如何将图像发布到Web服务器,第1张

概述我正在使用json解析来处理Web服务.我能够从网络服务中获取图像,有人可以帮助我发布图像吗?我如何将图像发布到Web服务? 在这里找到服务器端( PHP)编码图像上传随机名称.它也会将图像链接作为响应. //Create a folder named images in your server where you want to upload the image.// And Create a 我正在使用Json解析来处理Web服务.我能够从网络服务中获取图像,有人可以帮助我发布图像吗?我如何将图像发布到Web服务?@R_419_6120@ 在这里找到服务器端( PHP)编码图像上传随机名称.它也会将图像链接作为响应.

//Create a folder named images in your server where you want to upload the image.// And Create a PHP file and use below code .<?PHP$uploaddir = 'images/';$ran = rand () ;$file = basename($_fileS['userfile']['name']);$uploadfile = $uploaddir .$ran.$file;if (move_uploaded_file($_fileS['userfile']['tmp_name'],$uploadfile)) {        echo "www.host.com/.../images/{$uploadfile}";}?>

这是iOS代码

- (IBAction)uploadClicked:(ID)sender{    /*         turning the image into a NSData object         getting the image back out of the UIImageVIEw         setting the quality to 90        */        NSData *imageData = UIImageJPEGRepresentation(imageVIEw.image,90);        // setting up the URL to post to        Nsstring *urlString = @"your URL link";        // setting up the request object Now        NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];        [request setURL:[NSURL URLWithString:urlString]];        [request sethttpMethod:@"POST"];        /*         add some header info Now         we always need a boundary when we post a file         also we need to set the content type         You might want to generate a random boundary.. this is just the same          as my output from wireshark on a valID HTML post        */        Nsstring *boundary = [Nsstring stringWithString:@"---------------------------14737809831466499882746641449"];        Nsstring *ContentType = [Nsstring stringWithFormat:@"multipart/form-data; boundary=%@",boundary];        [request addValue:ContentType forhttpheaderFIEld: @"Content-Type"];        /*         Now lets create the body of the post        */        NSMutableData *body = [NSMutableData data];        [body appendData:[[Nsstring stringWithFormat:@"rn--%@rn",boundary] dataUsingEnCoding:NSUTF8StringEnCoding]];            [body appendData:[[Nsstring stringWithString:@"Content-disposition: form-data; name="userfile"; filename="ipodfile.jpg"rn"] 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]];        // setting the body of the post to the reqeust        [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);}
总结

以上是内存溢出为你收集整理的iPhone – 如何将图像发布到Web服务器全部内容,希望文章能够帮你解决iPhone – 如何将图像发布到Web服务器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1027640.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存