如何将UIImage上传到服务器上?

发布于 2024-10-02 02:03:12 字数 203 浏览 7 评论 0原文

我是 iphone 新手,是否可以在不使用任何 php 或其他文件的情况下将 uiimage 上传到服务器上。

我得到了通过向某些 php 文件发送请求来上传图像的示例。 但我不想使用 php 文件。

我在服务器上有服务器路径和上传文件夹。

任何人都可以有解决方案仅使用 iPhone 将图像上传到服务器吗?
任何想法都将受到高度赞赏。

I am new to iphone, Is it possible to upload uiimage on server without using any php or other files.

I got may examples of uploading image by sending request to some php file.
But i don't wants to use php files.

I have server path and Upload folder on server.

Can Anyone has solution to upload image on server with only using iphone ??
Any Idea is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小忆控 2024-10-09 02:03:12

您要将照片上传到哪里?需要有一个服务器端脚本来接收文件,通常是 PHP、Perl 或 Python 脚本。

Where are you uploading a photo to? There needs to be a server side script to receive the file, typically a PHP, Perl, or Python script.

失去的东西太少 2024-10-09 02:03:12
func UploadImageWithDict(#Dict : NSMutableDictionary ,Image : UIImage) -> NSMutableDictionary
{
    var imageData = UIImageJPEGRepresentation(Image,0.1)
    if (imageData != nil)
    {
        var request = NSMutableURLRequest(URL: NSURL(string:””)!)
        var boundary = NSString(format: "---------------------------14737809831466499882746641449")
        request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
        let body = NSMutableData.alloc()
        var postData:String = String()

        postData += "--\(boundary)\r\n"
        for (key, value : AnyObject) in Dict {
            if let value = value as? String {
                postData += "--\(boundary)\r\n"
                postData += "Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n"
                postData += "\(value)\r\n"
            }
        }
        postData += "--\(boundary)\r\n"
        postData += "Content-Disposition: form-data; name=\"photo\"; filename=\"\(Int64(NSDate().timeIntervalSince1970*1000)).jpg\"\r\n"
        postData += "Content-Type: image/jpeg\r\n\r\n"

        body.appendData(postData.dataUsingEncoding(NSUTF8StringEncoding)!)
        body.appendData(imageData)
        postData = String()
        postData += "\r\n"
        postData += "\r\n--\(boundary)--\r\n"
        body.appendData(postData.dataUsingEncoding(NSUTF8StringEncoding)!)

        request.HTTPMethod = "POST"
        request.HTTPBody = body

        var Err: AutoreleasingUnsafeMutablePointer<NSError? > = nil
        var returnData: NSData? = NSURLConnection.sendSynchronousRequest(request, returningResponse:nil , error:Err)

        if(Err == nil && returnData != nil)
        {
            print(">>>>>>>>>")
            var returnString = NSString(data: returnData!, encoding: NSUTF8StringEncoding)
            var data : NSData? = StringData.dataUsingEncoding(NSUTF8StringEncoding)
            var dict : AnyObject? = NSJSONSerialization.JSONObjectWithData(data!,options:NSJSONReadingOptions.AllowFragments, error: nil)
            print(dict)
            return dict as! NSMutableDictionary
        } 
        else
        {
            return NSMutableDictionary()
        }
    }
    else
    {
        return NSMutableDictionary()
    }
}
func UploadImageWithDict(#Dict : NSMutableDictionary ,Image : UIImage) -> NSMutableDictionary
{
    var imageData = UIImageJPEGRepresentation(Image,0.1)
    if (imageData != nil)
    {
        var request = NSMutableURLRequest(URL: NSURL(string:””)!)
        var boundary = NSString(format: "---------------------------14737809831466499882746641449")
        request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
        let body = NSMutableData.alloc()
        var postData:String = String()

        postData += "--\(boundary)\r\n"
        for (key, value : AnyObject) in Dict {
            if let value = value as? String {
                postData += "--\(boundary)\r\n"
                postData += "Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n"
                postData += "\(value)\r\n"
            }
        }
        postData += "--\(boundary)\r\n"
        postData += "Content-Disposition: form-data; name=\"photo\"; filename=\"\(Int64(NSDate().timeIntervalSince1970*1000)).jpg\"\r\n"
        postData += "Content-Type: image/jpeg\r\n\r\n"

        body.appendData(postData.dataUsingEncoding(NSUTF8StringEncoding)!)
        body.appendData(imageData)
        postData = String()
        postData += "\r\n"
        postData += "\r\n--\(boundary)--\r\n"
        body.appendData(postData.dataUsingEncoding(NSUTF8StringEncoding)!)

        request.HTTPMethod = "POST"
        request.HTTPBody = body

        var Err: AutoreleasingUnsafeMutablePointer<NSError? > = nil
        var returnData: NSData? = NSURLConnection.sendSynchronousRequest(request, returningResponse:nil , error:Err)

        if(Err == nil && returnData != nil)
        {
            print(">>>>>>>>>")
            var returnString = NSString(data: returnData!, encoding: NSUTF8StringEncoding)
            var data : NSData? = StringData.dataUsingEncoding(NSUTF8StringEncoding)
            var dict : AnyObject? = NSJSONSerialization.JSONObjectWithData(data!,options:NSJSONReadingOptions.AllowFragments, error: nil)
            print(dict)
            return dict as! NSMutableDictionary
        } 
        else
        {
            return NSMutableDictionary()
        }
    }
    else
    {
        return NSMutableDictionary()
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文