阿里云
发表主题 回复主题
  • 112阅读
  • 0回复

[求助]iOS阿里云上传图片不成功

级别: 新人
发帖
1
云币
2
O`N,aYo  
1]A\@(  
func ossUpload(_ image: UIImage, bucket: String, callback: @escaping (_ result: Any?, _ error: Any?) -> Void) { CDr0QM4k:.  
    var originData: Data? f'`y-]"V5)  
    var signType: String? s&wm^R  
    if let data: Data = UIImagePNGRepresentation(image) { l2wu>Ar7.  
        originData = data /c4$m3?]  
        signType = "image/png" Fta=yH }  
    } else if let data: Data = UIImageJPEGRepresentation(image, 1.0) { %N\8!aXnf  
        originData = data _. EM])b  
        signType = "image/jpeg" Y;dqrA>@  
    } else { X76rme  
        originData = nil :#D~j]pP  
        signType = nil ZH~Wn#Wp  
    } rbl^ aik  
     &=XK:+  
    if originData == nil || signType == nil { D  ,[yx='  
        return I+31:#d  
    } :>F3es`  
)KGz -!1c  
RE1M4UV.  
    let dateFormatter = DateFormatter() "8~PfLJ+  
    dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss" (6b0rqPF  
    dateFormatter.timeZone = NSTimeZone(name: "UTC")! as TimeZone p|@#IoA/e  
    dateFormatter.locale = Locale(identifier: "en-US") mA@!t>=oMq  
    let date = dateFormatter.string(from: Date()) {qOqtkj  
     /rky  
    let digest = OSSUtil.dataMD5String(originData!) y>)c?9X  
    let sign = "PUT\n\(digest!)\n\(signType!)\n\(date) GMT" _]{LjJ!M  
nzbAQ3v  
T|0d2aa  
    HWNetwork.request(target: .autograph(md5File: digest!, name: "123.jpg", mime: sign, type: "800"), success: { (result) in t0Jqr)9}6  
        let json = JSON(result) wuW{ 2+)B  
        print("json===\(json)") //ios-upload-image ]&dPY[~,/i  
        if let path = json["data"]["path"].string{ Q7i(M >|O  
            callback(path, nil) 9A/bA|$  
            return EY:H\4)  
        } 5:C>:pAV  
        if let bucket = json["data"]["bucket"].string{ |o'r?"  
            if let graph = json["data"]["graph"].string{ xW2?\em  
                 ,eWLig  
                let endpoint = "https://oss-cn-shenzhen.aliyuncs.com" X(\L1N  
L&~'SC  
/Z,hQ>/  
                let provider = OSSCustomSignerCredentialProvider.init(implementedSigner: { (result, error) -> String? in 6As%<g=  
                    return graph YBR)S_C$_  
                }) F^`+.G\  
0s\ -iub=d  
<q>d@Foi  
                let client = OSSClient(endpoint: endpoint, credentialProvider: provider!) (E,Ibz2G:e  
                let put = OSSPutObjectRequest() '@Yp@ _  
                put.bucketName = bucket e`q*'u1?  
                 `j!_tE`  
                if let url = json["data"]["url"].string{ $EEn]y  
     TdT`V f  
                    put.objectKey = String(url[url.index(url.startIndex, offsetBy: 1)..<url.endIndex]) p \9}}t7n  
                    put.uploadingData = originData! r-*6# "  
                    put.objectMeta = ["Date": "\(date) GMT"] = ^Vp \  
                     ek]nLN  
                    uploadQueue.async { /oLY\>pD  
                         ^E:-Uy  
                        let task = client.putObject(put) x<' $  
                        task.continue({ (task:OSSTask) -> Any? in .\&k]}0qA?  
                 BW}M/  
                            if task.error == nil { ewHs ]V+U  
                                callback(url, nil) -A=3W3:C  
                                App.apollo.perform(mutation: CreateAttachmentMutation(path: url, md5: digest!, size: Long(originData!.count), width: Long(image.size.width), height: Long(image.size.height), isImage: true)) { (_, _) in V aG Qre  
                                    // pass /&_q"y9  
                                    print("success") {@3v$W~7M  
                                } &43c/T Sb  
                            } else { ZoSyc--Bv  
                                print("task error-----\(task.error!)") pek=!nZ  
                                callback(nil, "error") c:&8B/  
                            } `wQs$!a  
                            return nil 9V[}#(f$  
                        }).waitUntilFinished() x[&<e<6  
                    } u@`a~  
                } u[Si=)`VPk  
                 =QbOvIq  
            } ,UNk]vd  
        } @"1Z;.S8V  
    }) { (error) in c@"FV,L>  
        callback(nil, error) 32?'jRN(ue  
    } o3GkTn O  
} )S 4RR2Q>  
D,[Nn_N  
P=KhR&gwV~  
.`5|NUhN  
HKI\i)c  
这是我的json打印信息 $/tj<++W  
a0gg<Ml  
json==={ s%`l>#H  
  "code" : 0, iLNUydiS  
  "data" : { lS7L|  
    "graph" : "OSS LTAIBlPDFHyjlxfD:PsbFOVd86djrovoyS3eHpc54bu0=", qe&B$3D|  
    "url" : "\/icon\/3569686715190237_1531302723861.jpg", \k`9s q  
    "bucket" : "huiwan-test" ^v'0\(H?P  
  }, 9d-'%Q>+  
  "message" : "success" %.r \P@7/Q  
} _ahp7-O  
f!R7v|j P  
oYTLC@98}  
这是报错,不知道签名哪不匹配了。似乎动被截取了一部分? 'j, ([  
5QuRwu_  
n8=D zv0  
task error-----Error Domain=com.aliyun.oss.serverError Code=-403 "(null)" UserInfo={__name=Error, HostId=huiwan-test.oss-cn-shenzhen.aliyuncs.com, Code=SignatureDoesNotMatch, OSSAccessKeyId=LTAIBlPDFHyjlxfD, RequestId=5B45D3448EE2472B572FAEDA, StringToSign=PUT 1Q!^*D  
:q*w_*w  
AG9DJ{T  
image/jpeg LQ4:SV'3  
Wed, 11 Jul 2018 09:52:03 GMT wv."  
yq[/9PciA  
/huiwan-test/icon/3569686715190237_1531302723861.jpg, StringToSignBytes=50 55 54 0A 0A 69 6D 61 67 65 2F 6A 70 65 67 0A 57 65 64 2C 20 31 31 20 4A 75 6C 20 32 30 31 38 20 30 39 3A 35 32 3A 30 33 20 47 4D 54 0A 2F 68 75 69 77 61 6E 2D 74 65 73 74 2F 69 63 6F 6E 2F 33 35 36 39 36 38 36 37 31 35 31 39 30 32 33 37 5F 31 35 33 31 33 30 32 37 32 33 38 36 31 2E 6A 70 67, SignatureProvided=PsbFOVd86djrovoyS3eHpc54bu0=, Message=The request signature we calculated does not match the signature you provided. Check your key and signing method.} `y^\c#k  
h ~yTkN]  
发表主题 回复主题
« 返回列表上一主题下一主题

限100 字节
批量上传需要先选择文件,再选择上传
 
验证问题: ECS是阿里云提供的什么服务? 正确答案:云服务器
上一个 下一个