【问题标题】:how to save local image to online database [duplicate]如何将本地图像保存到在线数据库[重复]
【发布时间】:2013-03-06 08:57:49
【问题描述】:

我正在创建我正在拍照的 iPhone 应用程序。现在我想在线保存这张照片(比如链接 www.test.com/myiPhoneAppImages/)。

知道如何将图像从 iPhone 拍摄到网站吗?

我尝试用谷歌搜索它,但没有找到任何有用的 tuts。

任何帮助/建议都会非常有用。

【问题讨论】:

    标签: iphone ios image ios6


    【解决方案1】:
    【解决方案2】:

    尝试以下方法将图像发布到服务器

    - (void) doPostImage
    
    {
        NSAutoreleasePool   *pool                       = [[NSAutoreleasePool alloc]init];
    
        //Add your images here...
        NSArray *imageParams = [NSArray arrayWithObjects:@"myimage1.png", nil];
    
    
    
        NSString *urlString = @"http://yourURL";
    
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    
        [request setURL:[NSURL URLWithString:urlString]];
    
        [request setHTTPMethod:@"POST"];
    
    
    
        NSMutableData *body = [NSMutableData data];
    
    
    
        NSString *boundary = @"---------------------------14737809831466499882746641449";
    
        NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
    
        [request addValue:contentType forHTTPHeaderField:@"Content-Type"];
    
    
        // add the image form fields
    
        for (int i=0; i<[imageParams count]; i++) {
    
            [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
            [body appendData:[[NSString stringWithFormat:@"Content-Disposition: attachment; name=\"image%d\"; filename=\"%@\"\r\n", i, [imageParams objectAtIndex:i]] dataUsingEncoding:NSUTF8StringEncoding]];
    
            [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    
            [body appendData:[NSData dataWithData:UIImageJPEGRepresentation(m_ImgVw_SelectedImage.image, 90)]];
    
            [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    
        }
    
        // add the text form fields
    
    
        // close the form
            [body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    
        // set request body
           [request setHTTPBody:body];
    
    
    
        // send the request (submit the form) and get the response
    
        NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
        [request release];
    
        NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    
    
    
        if(returnString)
        {
            [m_ctrlActivityView stopAnimating];
            NSString *m_strMessage=[NSString stringWithFormat:@" Your image is recieved"];
            [returnString release];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Thank you" message:m_strMessage delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"Error in server communication. Try again later" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
            [alert release];
    
        }
    
    
        CFRunLoopRun();
    
    
        [pool release];
    }
    

    【讨论】:

      【解决方案3】:

      您可以在搜索引擎中搜索它。

      数据方式:手机图片-----上传到网站-----由网站逻辑保存到数据库。

      顺便说一句,你不需要自己编写上传逻辑,AFNetworking 对你来说是一个很酷的第三方框架。 GitHub link

      【讨论】:

        猜你喜欢
        • 2018-04-14
        • 2020-04-07
        • 1970-01-01
        • 2021-02-23
        • 1970-01-01
        • 2015-12-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多